Solved

TDBGRID ROWS

Posted on 2004-09-06
7
379 Views
Last Modified: 2010-04-05
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

0
Comment
Question by:Balshe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11988474
you can use

dbgrid.datasource.dataset.locate(fieldname,value,[locaseinsensitive,lopartialkey]);
0
 
LVL 1

Author Comment

by:Balshe
ID: 11988515
That was quick:)

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



0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11988562
call dbgrid.SelectedRows.CurrentRowSelected := True; after the locate
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 75 total points
ID: 11988574
and then to show the focus simply call DbGrid.setfocus
0
 
LVL 11

Expert Comment

by:calinutz
ID: 11988590
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
 
LVL 1

Author Comment

by:Balshe
ID: 11988830
thanks
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11988841
Glad to have helped you :)

F68 ;-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 160
Delphi: ForceDirectory plain function 7 88
Base1 Encode/Decode 3 100
Firemonkey DbLookupComboBox equivalent ? 2 79
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question