Board index » delphi » Select Rows DBGrid

Select Rows DBGrid

I've seen all the examples of how to use selectedrows to get selected rows
in a grid, but..
I want to do the opposite. To select multiple rows in a grid with code.....

The idea is to doubleclick an row in the grid, then set all the rows in the
grid that matches a certain criteria, selected.

(Argh!! Selectedrows i readonly)

any ideas anyone?

Mogu

 

Re:Select Rows DBGrid


Quote
In article <7o9asb$o...@forums.borland.com>, Morten wrote:
> The idea is to doubleclick an row in the grid, then set all the rows in the
> grid that matches a certain criteria, selected.

The following example uses the DBDemos Orders table and selects all rows with
CustNo greater or equal to that of the clicked row:

  procedure TForm1.DBGrid1DblClick(Sender: TObject);
  var v: double;
  begin
    v := Table1CustNo.AsFloat;
    Table1.DisableControls;
    try
      Table1.First;
      while not Table1.EOF do begin
        DBGrid1.SelectedRows.CurrentRowSelected := (Table1CustNo.AsFloat >=
v);
      Table1.Next;
      end;
      if DBGrid1.SelectedRows.Count > 0 then
        Table1.GotoBookmark(pointer(DBGrid1.SelectedRows.Items[0]));
    finally
      Table1.EnableControls;
    end;
  end;

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03)
 (Unsolicited e-mail replies will most likely be ignored)

Other Threads