Topic: Select visible rows only

Hi all,

I need script on button click to select all visible rows from Form1.TableGrid1. I tried with this script but it selects only last visible row

procedure Form1_Button9_OnClick (Sender: TObject; var Cancel: boolean);
var vr: integer;

begin

  for vr := 0 to form1.tablegrid1.rowcount -1 do
  if (form1.tablegrid1.cell[12,vr].AsString = 'show') then
      form1.tablegrid1.SelectedRow := vr;


end;

Thanks,
Vladimir

Re: Select visible rows only

try changing

form1.tablegrid1.SelectedRow := vr;

to

form1.tablegrid1.Row[vr].Selected := True;

and see if that's what you want to do.

brian

3 (edited by amadeus.games 2020-10-10 13:31:29)

Re: Select visible rows only

Hi Brian,

In this case, there is no rows selected.

Re: Select visible rows only

procedure Form1_Button2_OnClick (Sender: TObject; var Cancel: boolean);
var
i:integer;
begin

  for i:=0 to Form1.TableGrid1.RowCount-1 do
      if (Form1.TableGrid1.RowVisible[i]=True) then Form1.TableGrid1.Selected[i]:=True;

end;

5 (edited by amadeus.games 2020-10-10 15:16:18)

Re: Select visible rows only

Hi Sib,

It's strange... When I first start application and when there are not rows selected in TableGrid1, when I click button, it selects all rows (visible and hidden). If i click on one row in table (manually select row) and then click button, script works (then it selects only visible rows).

Re: Select visible rows only

amadeus.games wrote:

Hi Sib,

It's strange... When I first start application and when there are not rows selected in TableGrid1, when I click button, it selects all rows (visible and hidden). If i click on one row in table (manually select row) and then click button, script works (then it selects only visible rows).

I can't help without a project