Selected Rows

Hello,

i have selected records in my datagrid,

but when i loop through the records and test if selected with “if gridInvoice.SelectedRows[i] then”,

it shows that only 1 record is selected, but i have selected multiple!

What can i do?

Can you provide some insights which selection method you have used?

Yes i have used the mode “gsmDisjunctRow” and ui grid selection, not selection in code

Hi,

Tested this here, couldn’t see an issue (connected to a TClientDataSet)

procedure TForm10.Button1Click(Sender: TObject);
begin
  for var I := 0 to TMSFNCDataGrid1.RowCount - 1 do
  begin
    if TMSFNCDataGrid1.SelectedRows[I] then
      TTMSFNCUtils.Log(I.ToString);
  end;
end;

procedure TForm10.FormCreate(Sender: TObject);
begin
  TMSFNCDataGrid1.BeginUpdate;
  TMSFNCDataGrid1.Options.Selection.Mode := gsmDisjunctRow;
  TMSFNCDataGrid1.EndUpdate;
end;

is it possible that i should use a clientDataSet instead of the connection to database via DataAdapter>DataSource>Table ?

I have observed that after i selected the rows and the dialog for reports is created, the selection disappears.

What can cause this behavior?

How can be corrected?

Thanks for helping Adrian

What you mean with this approach:

I could use a list with the ID: When selecting a row i add the id of this row to the list.

Finally, i use the list id’s to locate the selected rows.

Indeed, that’s a good approach. Attached a sample that shows how to get the ID and keep track of the selected IDs. This sample also applies and accepts selected rows as filtered rows.

Demo.zip (80.4 KB)

Thank you Pieter very much for the sample.

But now i have seen a strange behavior:

  • When i select the rows top down, only one row is selected
  • But when i select the rows bottom up, all rows are correctly selected

What to do there?

Thanks, i could solve the problem, in event SelectCell i have changed the code from AStartCell to

SelectedMasterRow := AFocusedCell.Row;

1 Like

Thanks for the additional feedback!