Frequently Asked Component Specific Questions
Options |
|
Display all FAQ items |
Displaying items 1 to 1 of 1, page 1 of 1
<< previous next >>

TAdvStringGridGetting checked rows in a filtered grid
In a filtered grid with a checkbox column, when you want to retrieve the rows with a selected checkbox, you need to use the real row index to get the selected state, not the display row index.
This sample code applied to a default TAdvStringGrid demonstrates this:
// initialize the grid
procedure TForm1.FormCreate(Sender: TObject);
begin
AdvStringGrid1.SaveFixedCells := false;
AdvStringGrid1.LoadFromCSV(''e:\tms\temp\cars.csv'');
AdvStringGrid1.FilterDropDownAuto := true;
AdvStringGrid1.FixedCols := 0;
AdvStringGrid1.AddCheckBoxColumn(0);
AdvStringGrid1.Options := AdvStringGrid1.Options + [goEditing];
end;
// loop through all rows and for rows with a checked checkbox, add the 2nd column cell value to a listbox:
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
state: boolean;
begin
for I := 1 to AdvStringGrid1.RowCount - 1 do
begin
AdvStringGrid1.GetCheckBoxState(0,AdvStringGrid1.RealRowIndex(i),state);
if state then // add value of cell in column 2 for selected rows to the listbox
listbox1.Items.Add(AdvStringGrid1.Cells[2,i]);
end;
end;