Solved

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

Posted on 2011-03-15
6
596 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 119
Mydac connection data base issue 3 156
Communication Between RC4 Delphi <-> PHP 3 113
Reconfigure Delphi Install? 2 51
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

6 Experts available now in Live!

Get 1:1 Help Now