Link to home
Start Free TrialLog in
Avatar of Balshe
Balshe

asked on

TDBGRID ROWS

Hi all

I want to  move through all rows of DBGrid(TDBGRID)  to find a record that matches my search criteria ,then if I found the row I want --> I want to select it and show it if it's hidden .

How can I do that??


Thanks

Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

you can use

dbgrid.datasource.dataset.locate(fieldname,value,[locaseinsensitive,lopartialkey]);
Avatar of Balshe
Balshe

ASKER

That was quick:)

 dbgrid.datasource.dataset.locate(fieldname,value,[locaseinsensitive,lopartialkey]); -->this solves the find issue  
 
how about selecting the row??



call dbgrid.SelectedRows.CurrentRowSelected := True; after the locate
ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

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
If you want to scroll through the Grid... searching for the field that matches your criteria you could do a slow search, using FindNext. If you use that then you will see the Grid values scrolling and stopping at your desired value.

Something like:
var
pk:string;
...

// suppose the field that is primary key is on the first position in the grid
Q1.Active:=false;
Q1.Active:=true;
Q1.FindLast;
//here remember the last record value of the primary key
pk:=DBGrid1.Fields[0].AsString;
Q1.FindFirst;

repeat
if (DBGrid1.Fields[0].AsString<>pk) and (criteria is not fullfilled) then Q1.findNext;
until (criteria is fullfilled) or (DBGrid1.Fields[0].AsString=pk);

This will select the record that fullfills the criteria you requested


This works slow on large datasets, so I would only use it on small ones
Avatar of Balshe

ASKER

thanks
Glad to have helped you :)

F68 ;-)