TMSFNCGrid - Problem using checkboxes on group header rows

Hi,
I'm having problems using the AutoCheckGroup option in grouped grids. It's a bit of random behavior, but I've managed to find a sequence of steps that lead to this error.
1 - Click on button Group
2 - Click on the checkbox of the first group (works correctly)
3 - Collapse the first group
4 - Click on the checkbox for the second group - Doesn't work!

I've created a small example (
Grouping.zip (14.7 KB)
) using code from the TMS FMX/Grid/Grouping Demo.

I'm using the following versions
FNC UI Pack - v5.5.0.1
Delphi - Delphi 12 Version 29.0.51961.7529

I compiled the test application in FireMonkey and tested it in Win32

Hi,
i runned your demo under Win32 with Delphi 11.

The problem is here

procedure TForm130.Button1Click(Sender: TObject);
begin
  if not FGrouped then
  begin

    TMSFNCGrid1.SortData(1,sdAscending);

    TMSFNCGrid1.Options.Grouping.MergeHeader := true;
    TMSFNCGrid1.Options.Grouping.Summary := true;
    TMSFNCGrid1.Group(1); <<<<------ PROBLEM -----

    TMSFNCGrid1.GroupSum(6);
    TMSFNCGrid1.GroupAvg(5);
    TMSFNCGrid1.Options.Sorting.Mode := gsmNormal;
    TMSFNCGrid1.AddCheckBoxColumn(1);
  end
  else
  begin
    TMSFNCGrid1.UnGroup;
    TMSFNCGrid1.Options.Sorting.Mode := gsmNone;
    TMSFNCGrid1.UpdateGridCells;
  end;

  FGrouped := not FGrouped;
  Button2.Visible := FGrouped;
  if FGrouped then
    Button1.Text := 'Ungroup'
  else
    Button1.Text := 'Group';
end;

Each time you call TMSFNCGrid1.Group(1) all cells are cleared (as tms source code).
So .... Until TMS does not fix this i do one work around not so "elegant" but works good in order to keep the selection.
The demo with changes is here
Demo_2024-06-07.zip (9.8 KB)

Is very problaby that TMSFNCGrid has somenthing native to keep the selection who i miss (or i did not find).

Last suggestion is to made "read only" the columns with checkbox because if you try to edit the cell seems that the cell's editor does not control that there is (or not) the check box. In this case the edit field goes up on the checkbox and the result is not so good to see.

Best regard
Daniele

Hello Daniele

You've attached the same files I sent :slight_smile:

Best regard
Lília

Hi Lila,
is not the same ... here the differences (in case for any reasons the modified file was not added to zip file :sweat_smile:)

Type TChekRow = record
        Rcd : Integer;
     end;

in form declaration

  private
    { Private declarations }
    FGrouped: Boolean;

    CheckedBoxState : array of TChekRow;
    procedure SaveCheckBoxState;
    procedure RestoreCheckBoxState;
procedure TForm130.SaveCheckBoxState;
var I : Integer;
begin
  CheckedBoxState:=nil;
  for I:=0 to TMSFNCGrid1.RowCount - 1 do // Skip header
  begin
    if TMSFNCGrid1.CheckBoxState[1,I] then
    Begin
      SetLength(CheckedBoxState,Length(CheckedBoxState) + 1);
      CheckedBoxState[High(CheckedBoxState)].Rcd:=I
    end;
  end;
end;

procedure TForm130.RestoreCheckBoxState;
var I : Integer;
begin
  for I:=0 to High(CheckedBoxState) do
  begin
    TMSFNCGrid1.CheckBoxState[1,CheckedBoxState[I].Rcd]:=True;
  end;
end;

and the end in a grouping button click

  if not FGrouped then
  begin

    TMSFNCGrid1.SortData(1,sdAscending);

    TMSFNCGrid1.Options.Grouping.MergeHeader := true;
    TMSFNCGrid1.Options.Grouping.Summary := true;
    TMSFNCGrid1.Group(1);

    TMSFNCGrid1.GroupSum(6);
    TMSFNCGrid1.GroupAvg(5);
    TMSFNCGrid1.Options.Sorting.Mode := gsmNormal;
    TMSFNCGrid1.AddCheckBoxColumn(1);
    RestoreCheckBoxState; ***** line to add
  end
  else
  begin
    SaveCheckBoxState; ***** line to add
    TMSFNCGrid1.UnGroup;
    TMSFNCGrid1.Options.Sorting.Mode := gsmNone;
    TMSFNCGrid1.UpdateGridCells;
  end;

Hope can help you ...

Regards
Daniele

Hi Daniele

Thanks for your reply :slight_smile:

Unfortunately the changes you suggested don't solve the problem. The code you sent allows the status of the checkbox not to be lost when grouping/ungrouping the grid. But that's not the problem I described.

The problem I described occurs when you close a group, and try to click on the checkbox of the next group, it doesn't work properly, it doesn't select the checkboxes of that group...

Best regards

Lília