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

LVL 1
BalsheAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Ferruccio AccalaiConnect With a Mentor Senior developer, analyst and customer assistance Commented:
and then to show the focus simply call DbGrid.setfocus
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
you can use

dbgrid.datasource.dataset.locate(fieldname,value,[locaseinsensitive,lopartialkey]);
0
 
BalsheAuthor Commented:
That was quick:)

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



0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
call dbgrid.SelectedRows.CurrentRowSelected := True; after the locate
0
 
calinutzCommented:
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
0
 
BalsheAuthor Commented:
thanks
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Glad to have helped you :)

F68 ;-)
0
All Courses

From novice to tech pro — start learning today.