Автор: Марина Прядко
Нам нужен StringGrid и 4 кнопки:
type TForm1 = class(TForm) StringGrid1: TStringGrid; AddColButton: TButton; DelColButton1: TButton; MoveColButton: TButton; DelColButton2: TButton; procedure AddColButtonClick(Sender: TObject); procedure DelColButton1Click(Sender: TObject); procedure MoveColButtonClick(Sender: TObject); procedure DelColButton2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type TAddDelStringGrid = class(TStringGrid) protected procedure RemoveColumn1(DelColumn: Integer);//Удаление (способ 1) procedure RemoveColumn2(DelColumn: Longint); //Удаление (способ 2) procedure AddColumn(NewColumn: Integer);//Добавление столбца procedure MoveColumn(FromIndex, ToIndex: Longint);//Перемещение end; var Form1: TForm1; implementation {$R *.dfm} procedure TAddDelStringGrid.RemoveColumn2(DelColumn: Longint); begin if DelColumn = FixedCols then begin if DelColumn = (ColCount - 1) then begin Cols[DelColumn].Clear; if ColCount<FixedCols + 1 then ColCount := (ColCount - 1); end end else begin Cols[DelColumn] := Cols[DelColumn + 1]; DeleteColumn(DelColumn + 1); end; end; procedure TAddDelStringGrid.RemoveColumn1(DelColumn: Integer); var Column: Integer; begin if DelColumn <= ColCount then begin Cols[DelColumn].Clear; for Column := DelColumn+1 to ColCount - 1 do Cols[Column - 1].Assign(Cols[Column]); ColCount := ColCount - 1; end; end; procedure TAddDelStringGrid.AddColumn(NewColumn: Integer); var Column: Integer; begin ColCount := ColCount + 1; for Column := ColCount - 1 downto NewColumn+1 do Cols[Column].Assign(Cols[Column - 1]); Cols[NewColumn].Text := ''; end; procedure TAddDelStringGrid.MoveColumn(FromIndex, ToIndex: Longint); begin inherited; end; //============================================================== procedure TForm1.AddColButtonClick(Sender: TObject); begin TAddDelStringGrid(StringGrid1).AddColumn(3); end; procedure TForm1.DelColButton1Click(Sender: TObject); begin TAddDelStringGrid(StringGrid1).RemoveColumn1(3); end; procedure TForm1.DelColButton2Click(Sender: TObject); begin TAddDelStringGrid(StringGrid1).RemoveColumn2(3); end; procedure TForm1.MoveColButtonClick(Sender: TObject); begin TAddDelStringGrid(StringGrid1).MoveColumn(1, 3); end;