Solved

Current record moves off screen in TDBGrid

Posted on 2007-04-06
2
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to define IfThen functions in one common unit? 4 79
creating threads in delphi 1 202
How to add columns to a RAD Studio FMX grid at design time 1 60
IP without any Dots 1 99
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 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