Link to home
Start Free TrialLog in
Avatar of evansj
evansj

asked on

Select a row in a DB Grid programmatically

How would you select a row in a dbgrid programmatically? Is there a property or method to do this?
Avatar of KE
KE

There's no straight way like "Row := 10";
You will have to locate the DataSet on the row you wish to select.
Try to be more specific, there may be a workaround.
Avatar of evansj

ASKER

What I'm looking for is a way to do the following:
for x: = 0 to dbgrid.rowcount - 1 do
begin
select the row, etc
end;
Please give more details, according to parameters you want to select a row?
The code below is actually equivalent to the code you need:

YourDataSet.First;
While not YourDataSet.EOF do
           YourDataSet.Next;

When every time the dataset's record is moved, the corresponding dbgrid row is selected.

You can set dgRowSelect and dgAlwaysShowSelection to True in the dbgrid's options, so you can see the selection at any time.

Regards,
Wang
     
ASKER CERTIFIED SOLUTION
Avatar of ronit051397
ronit051397

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of evansj

ASKER

Excellent the code snippet works great. What I'm doing is copying the entire dbgrid to the clipboard for import into Excel. I can already copy the data to the clipboard if the user holds the ctrl key and selects the individual row. Thanks much!!!