Solved

Current record moves off screen in TDBGrid

Posted on 2007-04-06
2
195 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 104
Delphi cmd execution 6 66
select query - oracle 16 100
Delphi: sending SMS on android platform 1 31
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

766 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