TTMSFNCDataGrid setting a ComboBox ItemIndex on my own

Another day - another problem.

I have a column where i wan't to use a ComboBox as editor. The Values in the ComboBox are different from that one in the grid. For exmpale:

ComboBoxValue "Bestellen" - GridValue "X"
ComboBoxValue "Melden" - GridValue "M"
ComboBoxValue "Gemeldet" - GridValue "G"

The ComboBoxIndex is picked based on the Cell-Value i guess?

I tried to set the ComboBoxIndex within TMSFNCDataGrid1GetInplaceEditorProperties but this does not have any effect.

You can easily check this with you "Basic-Editing"-Demo. I changed the GetInplaceEditorProperties-Code to set the Index of the ComboBox to a specific value:

  if AInplaceEditorType = getTrackBar then
    (AInplaceEditor as TTMSFNCDataGridTrackBar).Max := 3000
  else if AInplaceEditorType = getComboBox then
    (AInplaceEditor as TTMSFNCDataGridComboBox).ItemIndex := 1;

Excpectation: ComboBoxIndex is set to 1 (which would be in this case "Audi").

But it is always the entry Selected in the ComboBox, that is in the cell. (In my case with abbreviations in the GridCell, the ComboBoxIndex on opening is always -1).

Thank you

Chris

Hi,

So what happens is that in the OnGetInplaceEditorProperties, the setting of ItemIndex does not have any effect, because after this event, there is another event that transfers the value from the cell to the editor. The event is called OnCellEditGetValue, overriding the value used inside the combobox, so you can use

procedure TForm1.TMSFNCDataGrid1CellEditGetData(Sender: TObject;
  ACell: TTMSFNCDataGridCellCoord; AInplaceEditor: TTMSFNCDataGridInplaceEditor;
  var AValue: TTMSFNCDataGridCellValue);
begin
  if AInplaceEditor is TTMSFNCDataGridComboBox then
    AValue := 'Audi';
end;

Alternatively, after opening the inplace editor you can also use

procedure TForm1.TMSFNCDataGrid1AfterOpenInplaceEditor(Sender: TObject;
  ACell: TTMSFNCDataGridCellCoord; AInplaceEditor: TTMSFNCDataGridInplaceEditor;
  AValue: TTMSFNCDataGridCellValue);
begin
  if AInplaceEditor is TTMSFNCDataGridComboBox then
    (AInplaceEditor as TTMSFNCDataGridComboBox).ItemIndex := 1
end;
1 Like

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