I am using TMSFNCGrid for a task. I have to create rows in a grid with field and value pairs dynamically from code. I have to show a text field, a combo box field, a radio button group in this grid. I can do it successfully for a simple text field and combo box field.
But I didn't find a way to display a radio button group in a grid cell. Adding a simple radio button is possible. Is this feature possible with TMSFNCGrid? Could you throw some light on this topic? Thank you.
Thank you for the reply. I have been looking into your answer and grid events. I have still some questions:
In my scenario, I have to load dynamically text fields, checklistbox/radiogroup, and combo box onto the Grid cells with data from the database in specific cases. I can deal with text and combo box fields in a Grid.
Could you tell in which order should I have to use the events? I have to load a grid cell with texts in TChecklistbox and set its index and later when the index is changed I have to save it. Also looks like I have to use GetCellData, GetCellproperties, etc, at first rather than edit events.
Also after changing the index of a Tchecklistbox, maybe I need to call celleditGetData. What do you say? I am a bit puzzled. I hope it is clear what I meant. Thank you.
P.s : CellEditor class types with respect to CellEditGetData event (TWincontrol, TTMSFNCGridEditor) is contradicting the TMS FNC Grid Developer Guide and your above solution.
The above sample shows how to implement custom inplace editors. The events are called automatically when the grid cell is edited. If you want to manually map this on a dataset, you will need to call the appropriate field and update the value.
The value needs to be read from the database in the OnGetCellEditGetData and needs to be written to the database in the OnCellEditSetData. For example you would do something like this:
procedure TForm1.TMSFNCGrid1CellEditSetData(Sender: TObject; ACol,
ARow: Integer; CellEditor: TWinControl; var CellString: string);
begin
if CellEditor is TRadioGroup then
begin
CellString := (CellEditor as TRadioGroup).ItemIndex.ToString;
ClientDataSet1.FieldByName('MyField').AsString := CellString;
end;
end;
You would also need to set the correct record from the OnSelectCell event. You can take a look at the TTMSFNCGridDatabaseAdapter component to link it to a dataset automatically so you don't need to call the fields manually.