Solved

Current record moves off screen in TDBGrid

Posted on 2007-04-06
2
189 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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

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

13 Experts available now in Live!

Get 1:1 Help Now