How to get the text on filtered and checked row on TAdvStringgrid/TAdvColumnGrid.

How to get the text on filtered and checked row on TAdvStringgrid/TAdvColumnGrid.

My execution results:
Delphi 10.2, Open the the Demo -> AdvStringGrid -> aeg4 -> Asgdemo.dproj.
On the Filter tab. Add the 2 buttons, Button5 and Button6. Add the following code.
Then compile it.

And...
Select '>4 & <12' , Click Button4, Click Button5.
Then below is the message:

The results I want:
AdvStringGrid4.RowCount=15
[1]Audi
[5]BMW
[10]Honda
[22]TVR

Best regards.

----Add code----

procedure TDemo.Button5Click(Sender: TObject);
var
  i : integer;
  state: boolean;
  s : string;
begin
  s := 'AdvStringGrid4.RowCount=' + IntToStr(AdvStringGrid4.RowCount) + #13#10;
  for I := 1 to AdvStringGrid4.RowCount - 1  do
    if AdvStringGrid4.GetCheckBoxState(1,i,state) then
      if state then s := s + '['+IntToStr(i)+']'+AdvStringGrid4.Cells[0,I] + ' '+AdvStringGrid4.Cells[1,I] + #13#10;
  ShowMessage(s);
end;

procedure TDemo.Button6Click(Sender: TObject);
begin
  if radiogroup1.itemindex = 0 then
    AdvStringGrid1.SortSettings.Direction := sdAscending
  else
    AdvStringGrid1.SortSettings.Direction := sdDescending;
  AdvStringGrid1.SortSettings.Column := 1;
  AdvStringGrid1.QSort;
end;


Two possible solutions

  1. Set grid.FilterType = ftSuppress

or

  1. Use grid.DisplCells to access cell values
1 Like

Hi, Bruno.
Thanks for the quick support.

The first one worked. Thx.

I'm a little confused about the second method.
How can I get checks on/off with it?

001

procedure TForm1.Button1Click(Sender: TObject);
var
  i : integer;
  s : string;
begin
  s := 'AdvStringGrid1.RowCount=' + IntToStr(AdvStringGrid1.RowCount) + #13#10;
  for I := 1 to AdvStringGrid1.RowCount - 1  do
    s:= s + '['+IntToStr(i)+']'
          + '<'+AdvStringGrid1.DisplCells[1,I]+'>'
          + AdvStringGrid1.DisplCells[2,I] + #13#10;
   Showmessage(s);
end;

Using grid.GetCheckBoxState() but pass the real row index (using grid.RealRowIndex()) instead of the display row index (when you have grid.FilterType = ftHide).
Therefore, I suggest to use grid.FilterType = ftSuppress to avoid this conversion.

1 Like

Okay, thanks! :blush: