InsertControl (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The example shows how to add a control to a grid using the InsertControl method. To build this example, add a TDrawGrid object on the form. Add the code below to the form's constructor. The result is that a combo box is added in the second cell on the first row.

Code

procedure TForm1.FormCreate(Sender: TObject);
var
  combo :TComboBox;
  rect :TRect;
  edit: TEdit;
begin
  combo:=TComboBox.Create(self);//creates an instance of a ComboBox
  rect:=DrawGrid1.CellRect(2,0);//gets the Rectangle of the cell
  // sets the ComboBox location  
  combo.Top:=rect.Top;
  combo.Left:=rect.Left;

  DrawGrid1.InsertControl(combo);//insert the combo box to the grid
  DrawGrid1.ColWidths[2]:=combo.Width;///actualize the width of the whole column  

end;

Uses

Personal tools
Assistance