How can I make a comboedit (not only combobox) work? The following code is either wrong or incomplete.
Perhaps I have been misinformed. I got the follwing information from TMS by mail:
"Please use a custom editor. In FNC unfortunately etComboEdit is not available because the editing capabilities are not cross-framework. We have created our own TTMSFNCComboBox that is editable, so you can use it as a custom inplace editor."
So, how to make the ComboBox editable? It is not in my demo.
I really can't see any way to make the TTMSFNCComboBox editable. I don't see how to proceed after writing this code:
procedure TForm1.FormCreate(Sender: TObject);
begin
MyTMSGrid1.CellComboBox.Items.Add('Earth');
MyTMSGrid1.CellComboBox.Items.Add('Moon');
MyTMSGrid1.CellComboBox.Items.Add('Sun');
end;
procedure TForm1.MyTMSGrid1GetCellEditorType(Sender: TObject; ACol,
ARow: Integer; var CellEditorType: TTMSFNCGridEditorType);
begin
case ACol of
1: CellEditorType := etCustom; //etComboBox;
end;
end;
procedure TForm1.MyTMSGrid1GetCellEditorCustomClassType(Sender: TObject; ACol,
ARow: Integer; var CellEditorCustomClassType: TTMSFNCGridEditorClass);
begin
if ACol = 1 then
CellEditorCustomClassType := TTMSFNCComboBox;
end;
The grid just flickers when clicking in column 1, so it doesn't even drop down the item list.
In lazarus, the following code works as expected:
procedure TForm1.TMSFNCGrid1CellEditGetData(Sender: TObject; ACol, ARow: Integer; CellEditor: TTMSFNCGridEditor; var CellString: String);
begin
if ACol = 3 then
begin
(CellEditor as TTMSFNCComboBox).Items.Add('Online');
(CellEditor as TTMSFNCComboBox).Items.Add('Offline');
(CellEditor as TTMSFNCComboBox).Text := CellString;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i, j: Integer;
begin
//data
for i := 0 to TMSFNCGrid1.RowCount - 1 do
begin
for j := 0 to TMSFNCGrid1.ColumnCount - 1 do
begin
if i = 0 then
begin
if j < TMSFNCGrid1.ColumnCount - 1 then
TMSFNCGrid1.Cells[j, i] := Format('Column %d', [j])
else
TMSFNCGrid1.Cells[j, i] := 'Status';
end
else
begin
if j < TMSFNCGrid1.ColumnCount - 1 then
TMSFNCGrid1.Cells[j, i] := Format('(%d, %d)', [i, j])
else
TMSFNCGrid1.Cells[j, i] := IfThen(i mod 2 = 0, 'Online', 'Ofline');
end;
end;
end;
//events
TMSFNCGrid1.OnCellEditSetData := @TMSFNCGrid1CellEditSetData;
TMSFNCGrid1.OnGetCellEditorType := @TMSFNCGrid1GetCellEditorType;
TMSFNCGrid1.OnCellEditGetData := @TMSFNCGrid1CellEditGetData;
TMSFNCGrid1.OnGetCellEditorCustomClassType := @TMSFNCGrid1GetCellEditorCustomClassType;
end;
procedure TForm1.TMSFNCGrid1GetCellEditorType(Sender: TObject; ACol, ARow: Integer; var CellEditorType: TTMSFNCGridEditorType);
begin
if ACol = 3 then
CellEditorType := etCustom;
end;
procedure TForm1.TMSFNCGrid1CellEditSetData(Sender: TObject; ACol, ARow: Integer; CellEditor: TTMSFNCGridEditor; var CellString: String);
begin
CellString := (CellEditor as TTMSFNCComboBox).Text;
end;
procedure TForm1.TMSFNCGrid1GetCellEditorCustomClassType(Sender: TObject; ACol, ARow: Integer; var CellEditorCustomClassType: TTMSFNCGridEditorClass);
begin
if ACol = 3 then
CellEditorCustomClassType := TTMSFNCComboBox;
end;
Thank you. This code in Delphi 12 FMX does not work. There is just a flicker in the cell when clicking in coloumn 1.
ComboEditTest.zip (6.9 KB)