procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl);
begin
begin
{Method #1 --- use existing Combobox ---}
Combobox1.BoundsRect := (Sender as TStringGrid).CellRect(aCol,aRow);
Editor := ComboBox1;
{Method #2 --- create dynamically ---}
{Editor := (Sender as TStringGrid).EditorByStyle(cbsPickList) ;
TPickListCellEditor(Editor).Items.Assign(FieldList);
TPickListCellEditor(Editor).AutoDropDown := True;
TPickListCellEditor(Editor).AutoComplete := True;}
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FieldList := TStringList.Create;
FieldList.Add('Classes');
FieldList.Add('SysUtils');
FieldList.Add('Forms');
FieldList.Add('Controls');
FieldList.Add('Graphics');
FieldList.Add('Dialogs');
FieldList.Add('Grids');
ComboBox1.Items.Assign(FieldList);
StringGrid1.InsertRowWithValues(1,['','Classes','SysUtils','Forms','Dialogs']) ;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(FieldList);
end;
procedure TForm1.StringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer; var Value: string);
begin
{Method #1 --- use existing Combobox ---}
Combobox1.ItemIndex := Combobox1.Items.IndexOf(Value);
{Method #2 --- create dynamically ---}
//TPickListCellEditor((Sender as TStringGrid).Editor).ItemIndex := TPickListCellEditor((Sender as TStringGrid).Editor).Items.IndexOf(Value);
end;