Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-15
6
Medium Priority
?
605 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: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 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
  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
Industry Leaders: 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

782 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