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
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
ASKER
That was quick:)
dbgrid.datasource.dataset. locate(fie ldname,val ue,[locase insensitiv e,lopartia lkey]); -->this solves the find issue
how about selecting the row??
dbgrid.datasource.dataset.
how about selecting the row??
call dbgrid.SelectedRows.Curren tRowSelect ed := True; after the locate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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].AsSt ring;
Q1.FindFirst;
repeat
if (DBGrid1.Fields[0].AsStrin g<>pk) and (criteria is not fullfilled) then Q1.findNext;
until (criteria is fullfilled) or (DBGrid1.Fields[0].AsStrin g=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
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].AsSt
Q1.FindFirst;
repeat
if (DBGrid1.Fields[0].AsStrin
until (criteria is fullfilled) or (DBGrid1.Fields[0].AsStrin
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
ASKER
thanks
Glad to have helped you :)
F68 ;-)
F68 ;-)
dbgrid.datasource.dataset.