Hi all, How can we set and get value from a CellComboBox ? TIA
nobody knows how to set and get value from CellCombobox with TMSFMXGrid ? Thanks.
Pieter
(Pieter)
August 29, 2014, 2:43am
3
Hi,
Each editor is available in one of the various editing events. You can directly assign values to the CellComboBox or use the following approach:
procedure TForm1.TMSFMXGrid1CellEditGetData(Sender: TObject; ACol,
ARow: Integer; CellEditor: TFmxObject; var CellString: string);
var
cbo: TComboBox;
begin
cbo := (CellEditor as TComboBox);
cbo.BeginUpdate;
cbo.Items.Clear;
cbo.Items.Add('Item 1');
cbo.Items.Add('Item 2');
cbo.Items.Add('Item 3');
cbo.EndUpdate;
end;
procedure TForm1.TMSFMXGrid1GetCellEditorType(Sender: TObject; ACol,
ARow: Integer; var CellEditorType: TTMSFMXGridEditorType);
begin
CellEditorType := etComboBox;
end;
Kind Regards,
Pieter
Pieter Scheldeman2014-08-29 02:43:46
Ok i found to get selected value from CellCombox, we have to use OnCellComboCloseUp, but how can we select an item of the CellComboBox ?
Pieter
(Pieter)
August 29, 2014, 2:59am
5
When clicking in the cell the combobox should be displayed with the values that have been added.
Did you apply the above code?
Kind Regards,
Pieter
Sorry Pieter, il didin't read your response before my previous post. And my english is so bad that it's difficult to understand my question... sorry I want to select an item of a CellCombobox, how can we do that ? Thanks for your help
Yes i know how to fill combox in TMSFMXGrid, the combox is displayed, it works fine but i just want to select an item
Pieter
(Pieter)
August 29, 2014, 3:08am
8
It is unclear exactly what you mean with "select an item". The combobox should display when editing the cell, so it should be possible to select an item. Or do you mean that you want to display a combobox permanently?
Yes the user can select an item, but i want to do it by code. With your example : cbo.Items.Add('Item 1');
cbo.Items.Add('Item 2');
cbo.Items.Add('Item 3'); How can i select 'item 2' by code ? Is it possible to retrieve all the values in a row of a TMSFMXGrid with CellCheckBox and CellComboBox ?
Pieter
(Pieter)
August 29, 2014, 3:33am
10
You should normally be able to use the following code. It gets all the values for the column, and selects the value that matches the cell value.
procedure TForm1.TMSFMXGrid1CellEditGetData(Sender: TObject; ACol,
ARow: Integer; CellEditor: TFmxObject; var CellString: string);
var
cbo: TComboBox;
I: Integer;
begin
if CellEditor is TComboBox then
begin
cbo := CellEditor as TComboBox;
cbo.BeginUpdate;
cbo.Items.Clear;
for I := 1 to TMSFMXGrid1.RowCount - 1 do
cbo.Items.Add(TMSFMXGrid1.Cells[ACol, I]);
cbo.ItemIndex := cbo.Items.IndexOf(CellString);
cbo.EndUpdate;
end;
end;
procedure TForm1.TMSFMXGrid1GetCellEditorType(Sender: TObject; ACol,
ARow: Integer; var CellEditorType: TTMSFMXGridEditorType);
begin
CellEditorType := etComboBox;
end;