AdvStringGrid and GetCheckBoxState

Good morning to all,
one more problem with our AdvStringGrid ...
This problem is on GetCheckBoxState.
If the grid is NOT filtered the function works well, but if the grid is filterd (FilterActive:=True) the function has some problems.

Here a very simple demo program (delphi 10.3 / 10.4.1 with last tmsui version ) that show this behaviour,
GridCheckBox_2020-10-28.zip (7.5 KB)

Here some code (original one)

function TAdvStringGrid.GetCheckBoxState(ACol,ARow: Integer;var State: Boolean): Boolean;
var
  cg: TCellGraphic;
  cp: TCellProperties;
  //r: integer;
begin
  Result := False;

  if (NumHiddenRows > 0) then
  begin
    if FMouseActions.HotmailRowSelect and (ACol = 0) then
    begin
      State := RowSelect[ARow];
      Result := true;
    end
    else
    begin
//      cp := TCellProperties(Objects[ACol,ARow]);

      if FIsNarrowDown then
      begin
        cg := CellGraphics[ACol,ARow];
        if Assigned(cg) and (cg.CellType in [ctCheckBox, ctVirtCheckBox, ctDataCheckBox]) then
        begin
          state := cg.CellBoolean;
        end;
        Exit;
      end;

      cp := TCellProperties(GetAllGraphicsObject(ACol,ARow));
      if Assigned(cp) then
      begin
        cg := TCellGraphic(GetCPGraphicObject(cp));

        if Assigned(cg) then
        begin
          if (cg.CellType = ctCheckBox) then
          begin
            State := cg.CellBoolean; // *1
            Result := True;
          end;

          if (cg.CellType in [ctDataCheckBox,ctVirtCheckBox]) then
          begin
            State := AllCells[ACol,ARow] = GetCheckTrue(ACol,ARow);
            Result := True;
          end;

          if (cg.CellType = ctTriStateCheckBox) then
          begin
            State := AllCells[ACol,ARow] = GetCheckTrue(ACol,ARow);
            Result := True;
          end;
          if (cg.CellType = ctRowCheckBox) and (ACol = 0) then
          begin
            State := RowSelect[ARow];
            Result := True;
          end;
        end;
      end
      else
      begin
        cg := GetCellGraphic(ACol, ARow); // *2

        if cg = Nil then
          Exit;

In my program the in *1, even if the checkbox is checked, cg.CellBoolean is always false.
But in the demo project cp := TCellProperties(GetAllGraphicsObject(ACol,ARow)); return Nil and cg is nil and the function, even the checkbox is checked, return false (*2).

Thank's for attention

Regards
Daniele

Two solutions:

  1. Use the real row index for GetCheckBoxState() instead of the display index

or

  1. Set grid.FilterType = ftSuppress

Hi Bruno,
Solution 1 work well.
Excuse me for banal question .... but ftSuppress what kind of result does ? (i do not find any toipc in pdf manual...)

Thank's for your help

Daniele

Hi Bruno,
yes it's a filter type but wihis is/are the difference(s) between the two type ?

Thank's for attention

Daniele

Did you read the FAQ?

The grid has a new property FilterType that can be set to ftHide (default setting) or ftSuppress. With the default setting, during a filter operation the filtered rows are effectively hidden/removed from the grid, affecting the row indexes of all rows.

When the FilterType is set to ftSuppress, the filtered rows are just made invisible and are not affecting the row indexes. So, if you want to keep accessing grid cells with row indexes independent of filtering, the new option FilterType = ftSuppress can be used.

Hi Bruno,
thank's for explanation ...
In my opinion... the second one (ftSuppress) is very very interesed.
Weel done !!

Have a nice week end

Thank's
Daniele