Correct way to use checkbox column in TTMSFMXGrid

Hi
I have a TTMSFMXGrid without Data Bindings and column 0 is a
checkbox column (ColumnType is set to ctCheckBox) which represents a
Boolean array I am managing.  As far as I can tell the way to get/set
values in this array through the checkboxes is as follows

In GetCellData I have
   if ACol = 0 then MyGrid.CheckBoxState[ACol, ARow] := MyBooleans[ARow];

and in CellCheckBoxClick I have
  if ACol = 0 then
  begin
    MyBooleans[ARow] := not MyBooleans[ARow];
    MyGrid.CheckBoxState[Acol, ARow] := MYBooleans[ARow]; 
  end;

My question is - Is that the correct way to do it because it seems a bit awkward?  I did it this way because of two discoveries

1)  setting (Cell as TTMSFMXCheckGridCell).CheckBox.IsChecked in GetCellProperties triggered CellCheckBoxClick which made things very complicated.
2)  the value of (Cell as TTMSFMXCheckGridCell).CheckBox.IsChecked in CellCheckBoxClick seemed to to be set internally in a complicated way (i.e. I had no clue).

cheers
Jay

Hi, 


You could consider using the Booleans property instead, which automatically checks/unchecks the checkbox. If you wish to keep using your own MyBooleans property you'll need to use the OnGetCellProperties event to set the checkbox and the OnCellCheckBoxClick event to fill the MyBooleans array:

procedure TForm1.TMSFMXGrid1CellCheckBoxClick(Sender: TObject; ACol,
  ARow: Integer; Cell: TFmxObject);
begin
  if Cell is TTMSFMXCheckGridCell then
    MyBooleans[ARow] := (Cell as TTMSFMXCheckGridCell).CheckBox.IsCheckedProg;
end;

procedure TForm1.TMSFMXGrid1GetCellProperties(Sender: TObject; ACol,
  ARow: Integer; Cell: TFmxObject);
begin
  if Cell is TTMSFMXCheckGridCell then
    (Cell as TTMSFMXCheckGridCell).CheckBox.IsCheckedProg := MyBooleans[ARow];
end;


Thanks Pieter I'll do that.  IsCheckedProg is not covered in my TMS FMX Grid Developers Guide (December 2016)  which is the latest on the web site.  Any idea when an updated version will be published?

Hi Pieter

I've tried that and it doesn't work.  If you start off with MyBooleans all as true then the checkboxes all start off ticked but then when one of them is clicked to uncheck it the following happens

1)  CellCheckBoxClick is called twice;
2)  (Cell as TTMSFMXCheckGridCell).CheckBox.IsCheckedProg is true for both calls.

Is there a flow diagram that explains how IsCheckedProg and IsChecked are set and when CellCheckBoxClick is called?  I noticed that setting either triggers CellCheckBoxClick which is probably why the double call above (once when the user clicks and once because IsCheckedProg is set in GetCellProperties

If you amend your previous code as follows then you'll what I mean.

procedure TForm1.TMSFMXGrid1CellCheckBoxClick(Sender: TObject; ACol,
  ARow: Integer; Cell: TFmxObject);
begin
  if Cell is TTMSFMXCheckGridCell then
  begin
    if (Cell as TTMSFMXCheckGridCell).CheckBox.IsCheckedProg then ShowMessage('true') else ShowMessage('false');
    MyBooleans[ARow] := (Cell as TTMSFMXCheckGridCell).CheckBox.IsCheckedProg;
  end;
end;

Hi, 


We have tested this here, but the OnCellCheckBoxClick event is only triggered once. Are you using the latest version? If the problem persists, can you perhaps create a sample that is demonstrating this issue?

I've sent a sample project through to help@ email.  And confirming I am running Delphi 10.1 Berlin Update 2 on Windows 10 inside Parallels 12 on OSX Sierra and FMX UI pack is v3.5.3.0.