How to use a ComboBox editor in FNC DataGrid

I am having a terrible time trying to figure out how to use a combo box editor with the FNC DataGrid. I added a DataGrid to a new project and used the employee database. I wrote a select statement that displays the employee's department with the employee name in case that is way and ran out of steam of that going any further (I didn't have a way to load the department names as options for the dropdown).

So, I picked the JOB_GRADE column and just tried to display the displayed numbers as text in the DataGrid (not by changing SQL). I tried to use OnLoadCellData() as the manual said that would be to the way to take an encrypted value and display it in plain text. Unfortunately, it looks like OnLoadCellData() is never called (tested by putting a breakpoint on the first line of my code).

I tried setting the Editor property for the fourth column to getComboBox and entered the corresponding text of the numbers in the EditorItems property, but the ComboBox still doesn't show up.

Can you please show me how to display a functioning ComboBox in an FNC DataGrid? (If you've already done this on a video tell me which video and the starting time of demonstrating this.) Here is my project so far:
TestGridWithComboBox.zip (13.8 KB)

OnLoadCellData is triggered when loading data in the grid coming from sources such as CSV, TXT, JSON, ...

Maybe these topics can help you

Basically it comes down using the code like this

  TMSFNCDataGrid1.Columns[3].Editor := getComboBox;
  TMSFNCDataGrid1.Columns[3].AddSetting(gcsEditor);
  TMSFNCDataGrid1.Columns[3].EditorItems.Add('one');
  TMSFNCDataGrid1.Columns[3].EditorItems.Add('two');
  TMSFNCDataGrid1.Columns[3].EditorItems.Add('three');
  TMSFNCDataGrid1.Columns[3].AddSetting(gcsEditorItems);

This will show a combobox with the items when editing a cell.

Additionally, there are 2 events called when editing starts and stops, allow you to get / set data from and to the editor, such as specific values. This is demonstrated here in a custom editor example for the color wheel:

I work in C++ Builder, not Delphi. I read Delphi code (but haven't programmed in Pascal since I was in college back at UCSD 50 years ago, when Pascal was being written there) and I convert Delphi to C++ so I can do my work. The two ways I know how to convert that code both give me compile errors, so I am still stuck,

DataGrid->Columns[3].Editor = getComboBox; // [bcc64x Error] TestGridUnit.cpp(30): no member named 'Editor' in 'Vcl::Tmsfncdatagridrenderer::TTMSFNCDataGridColumns'

DataGrid->Columns->GetItem(3)->Editor = getComboBox; // [bcc64x Error] TestGridUnit.cpp(30): 'GetItem' is a private member of 'Vcl::Tmsfncdatagridrenderer::TTMSFNCDataGridColumns'

It almost looks like you need to expose the GetItem() function as public to be able to use the DataGrid in C++ unless you know some other way to code that in C++.

TMSFNCDataGrid1->Columns->Items[3]->Editor = getComboBox;

I used that sample as a rough guide and wrote the sample application. The problem is that OnCellEditSetData is never called (as verified by setting a breakpoint there) and therefor the application tries to store a string in a interger field. Can you help me figure out why OnCellEditSetData is never called and how to fix it?
TestGrid.zip (16.0 KB)

The events trigger as expected here, but you should not change properties of the grid inside events. Changing properties retrigger the calculation process. In events, you can only read from the grid or set properties of the parameters that are passed through the event. Filling the combobox items should be done dynamically in the OnGetInplaceEditorProperties, by accessing the inplace editor as a combobox and changing the items property.

this is demonstrated here

1 Like

That pointed out to me something I had not realized - the database adapter has events. Particularly, an event that captures the data from the database just before it reaches the DataGrid and another event that captures the data just after it leaves the DataGrid on its way back to the database. So, it is pretty easy to have integers stored in the database that get converted to strings that the user interacts with and those strings get converted back to integers before they reach the database.

So, the simplest way to do what I wanted is to work at the database adapter level. I am attaching my sample. There is very little that has to be done at the DataGrid level, in case someone else finds this approach easier.
TestGridUnit.zip (15.3 KB)

2 Likes

Thanks for sharing this. It's going to be helpful for other users as well.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.