Solved

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

Posted on 2011-03-15
6
593 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Bianca
Comment Utility
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
Comment Utility
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
Comment Utility
It was not accurate but it pointed me in the right direction.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How can I open IE in olecontainer? 7 108
System restore point 4 77
Delphi selector screen 2 57
Convert a string into a TDateTime 5 44
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

11 Experts available now in Live!

Get 1:1 Help Now