TTMSFMXGrid - update cell when another cell change

I am using event OnCellEditSetData to format a cell like this:


CellString := FloatToStrF(StrToFloat(CellString), ffExponent, Precision, Digits)

where Precision and Digits are given by the contents of other cells containing etSpinBox controls.

When a SpinBox changes, how do I update the cell whose format depends on the SpinBox value?

Hi, 


when the value of the spinbox changes, you can use the OnCellEditSetData event to update the other cell properties:

procedure TForm102.TMSFMXGrid1CellEditSetData(Sender: TObject; ACol,
  ARow: Integer; CellEditor: TFmxObject; var CellString: string);
begin

end;

Kind Regards, 
Pieter

Thank you. Using your suggestion, I have it working - almost! The problem is that the user seems to need to press enter or click outside the control beforeTMSFMXGrid1CellEditSetData fires. How can I have it fire as soon as the user makes a selection in a combobox or changes the value in a spinedit?

Hi,


You can accomplish this with the following code (spinbox):

procedure TForm1.FormCreate(Sender: TObject);
begin
  TMSFMXGrid1.CellSpinBox.OnChange := ValueChanged;
  TMSFMXGrid1.CellSpinBox.CanFocus := False;
end;

procedure TForm1.TMSFMXGrid1GetCellEditorType(Sender: TObject; ACol,
  ARow: Integer; var CellEditorType: TTMSFMXGridEditorType);
begin
  CellEditorType := etSpinBox;
end;

procedure TForm1.ValueChanged(Sender: TObject);
var
  cl: TCell;
begin
  cl := TMSFMXGrid1.FocusedCell;
  if Assigned(TMSFMXGrid1.CellSpinBox.Parent) and (cl.Col <> -1) and (cl.Row <> -1) then
  begin
    TMSFMXGrid1.Cells[cl.Col + 1, cl.Row] := FloatToStr(TMSFMXGrid1.CellSpinBox.Value);
  end;
end;

Unfortunately, the focus needs to stay on the grid, because when changing the value of the grid cell while the editor is active the editor will be hidden. This can be done by setting the CanFocus property to false as demonstrated in the above code.

Kind Regards, 
Pieter