Solved

Current record moves off screen in TDBGrid

Posted on 2007-04-06
2
190 Views
Last Modified: 2011-10-03
Hi all,

I have a simple data capture app (Delphi 5), which uses only master/ detail TADOTables and TDBNavigator components to manipulate data in a SQL Server (2000) database. The app uses TDBGrids connected to TADOQueries on each data capture page, to give the data capturer some context w.r.t. the data being entered. The queries typically display information taken from some of the tables which are being edited on any one data capture page in the app - it so happens that on some pages the entries in the query have a one to one relationship with the data in the Master dataset of that page.

I would like to have the record in the query corresponding to the current record in the master table highlighted. I have written the following code to do this:

--snip--

private
   CurrentPos: Integer;

--snip--

{This is the datasource connected to the Master dataset}
procedure TForm3.DataSource1DataChange(Sender: TObject; Field: TField);
begin
   CurrentPos := DataSource1.DataSet.RecNo;
end;

--snip--

procedure TForm3.DBGrid4DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if DBGrid4.DataSource.DataSet.RecNo = CurrentPos then
  begin
    DBGrid4.Canvas.Brush.Color := $006495ED;
    DBGrid4.DefaultDrawColumnCell(Rect,DataCol,Column,State);
  end;
end;

--snip--

My problem is that there are more records than available space on the grid, which causes the highlighted records to move off the page. The grid however, does not automatically scroll forward, causing the context I want to provide to the data capturer to be lost.

Is there any way of getting the grid to scroll forward when the current record goes off the page?

Lourens
0
Comment
Question by:lourens_walters
2 Comments
 

Author Comment

by:lourens_walters
ID: 18865198
Hi,

I have managed to solve the problem myself. Seeing as the record numbers in the master table correspond to those in the query, I used the following code to set record numbers in the DBGrid to correspond to those in the query:

procedure TForm3.DataSource1DataChange(Sender: TObject; Field: TField);
begin
   if (ADOQuery5.Active) then
      DBGrid4.DataSource.DataSet.RecNo := DataSource1.DataSet.RecNo;
end;

DataSource1 here is the datasource attached to the master table. When data changes I set the Record number for the DBGrid datasource i.e. the query, to correspond to the Master table. This ensures that the correct record in the DBGrid is highlighted.

Lourens
0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 18998859
lourens_walters,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

914 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

16 Experts available now in Live!

Get 1:1 Help Now