Solved

TDBGRID ROWS

Posted on 2004-09-06
7
369 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now