Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to focus selection on grid to a specific record using a passed variable?

Posted on 2011-03-15
Medium Priority
Last Modified: 2012-05-11
On FormShow of JobForm, I have a variable called sJobID (passed from previous grid). When JobForm shows, there is a grid within the form that shows multiple job records (multiple sJobIDs). I want the focus (highlight) to be on the passed variable sJobID.

How to do?
Question by:Bianca
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
  • 3
  • 2
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35140108
First search for the record in the dataset, then set the selected index

Try this
if Dataset1.Locate(JobID, sJobID, []) then
  DBGrid1.SelectedIndex := Dataset1.RecNo;

Open in new window

LVL 32

Accepted Solution

Ephraim Wangoya earned 1500 total points
ID: 35140134

In fact, come to think of it, you may only need to locate the record then set focus to the grid

if Dataset1.Locate(JobID, sJobID, []) then
LVL 24

Expert Comment

ID: 35140377
It's better to use the Dataset from the DBGrid:
procedure TForm1.FormShow(Sender: TObject);
  if not DBGrid.DataSource.DataSet.Active then

  DBGrid.DataSource.DataSet.Locate('FieldJobID',sJobID,[]); // FieldJobID if the field in the DB that holds all the JobIDs

Open in new window

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 35140383
Does this look right?
if gvActivities.DataController.Search.Locate(gvActivitiesctjobid, sJobID, []) then

I'm getting error, Incompatible Types 'Integer' and 'TcxDBGridColumn'

Author Comment

ID: 35140457
Actually just got it to work with this code:

    if gvActivities.DataController.Search.Locate(gvActivitiesctjobid.Index, sJobID) then

Thanks for pointing me in the right direction!

Author Closing Comment

ID: 35140462
It was not accurate but it pointed me in the right direction.

Featured Post

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!

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

705 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