Solved

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

Posted on 2011-03-15
6
595 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
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:ewangoya
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:
ewangoya 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 211
Newbie Thread Programming 1 139
Delphi: how to send PJL commands to printer 3 89
add combobox item based on numbers 9 124
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 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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

14 Experts available now in Live!

Get 1:1 Help Now