Solved

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

Posted on 2011-03-15
6
600 Views
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?
Thanks!
0
Comment
Question by:Bianca
[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
  • 3
  • 2
6 Comments
 
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
begin
  DBGrid1.SelectedIndex := Dataset1.RecNo;
  DBGrid1.SetFocus;
end;

Open in new window

0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 500 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
  DBGrid1.SetFocus;
0
 
LVL 24

Expert Comment

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

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

Open in new window

0
Technology Partners: 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!

 

Author Comment

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

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

Author Comment

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

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

Thanks for pointing me in the right direction!
0
 

Author Closing Comment

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

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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