Solved

Record Navigation using the DBGrid control

Posted on 1998-05-18
9
478 Views
Last Modified: 2010-04-06
I am sure I am being stupid but.......

I wish to navigate throught a dataset using the DBGrid control. This is not a problem except I do not know how to tell when a new record has been selected except by using the AfterScroll event on the table. As the table maybe scrolled for other reasons than a change in the record on the DBGrid I do not wish to use this. I wish, in essence, to emulate the OnClick event for the DBNav control.

Any ideas on how to do this?
0
Comment
Question by:ChrisBerry
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1346142
Hi

Your grid is presumably linked to a TDataSource, which is in turn linked to a TTable (or other TDataSet).  TTable has events AfterInsert, AfterPost, etc. which you could trap.

Regards,
JB
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1346143
Hi,

Well I was thing on the ondatachange event....

Regards, ZiF.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1346144
Forget something... you find OnDataChange event on TDataSource... and I meant Well I was thinking on the ondatachange event....
0
 

Author Comment

by:ChrisBerry
ID: 1346145
Sorry, some confusion here.

I can navigate fine through the records, what I cannot do is know, with an event, when the user has selected a new record.

I need to know this becaused I have a BLOB field in the record that needs processing every time the record is changed. But only from this DBGrid. The OnClick event in a DBNav does the job but then I have disable the DBGrid control to stop the user using it to navigate through the records. This is inconsistent with a related DBGrid where I have in a master/slave relationship and the user does needs access to the related records. It is also messy to disable the DBGrid because the scroll bar is available on the grid but does not work.

The master DBGrid is in ReadOnly mode all the time so data will not be changing.

I just feel I am missing something fundamental here as all I want to know is when the user selects another record in the DBGrid.

Cheers
0
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.

 
LVL 5

Expert Comment

by:JimBob091197
ID: 1346146
Hi Chris

The table linked to your grid has 2 events which should work: BeforeScroll and AfterScroll.

In your original question you say that you want to "emulate the OnClick event for the DBNav control" BUT without using the AfterScroll event.  I'm not sure why.  (What about BeforeScroll?)

The reason I say this is because when you click the DBNav control, it calls the dataset's (TTable or whatever) Next method.  The next method, triggers 2 events: BeforeScroll and AfterScroll.

JB
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1346147
You may write you own component inherit every from tdbGrid and try to trap the WM_VSCROLL windows message to do what you want there. I think it should work but I have not try it.


0
 

Author Comment

by:ChrisBerry
ID: 1346148
Hi Jim Bob,

I did not wish to use the AfterScroll or BeforeScroll methods because I use the table in other instances where I do not wish to process the Blob information. I could use a different table component just for the DBGrid work but then I have to syncronise the two tables and the only real way to do this is by searching the key fields, bookmarks do not work between tables as far as I know, so it all gets a bit messy.

kjteng,

I did think of doing this, I am just suprised that this event does not exist on the existing DBGrid as it makes a good record navigator.

CJB
0
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 50 total points
ID: 1346149
Hiya Chris,

   If have a similar issue and resolved it in the OnDataChange event of the datasource connected to the table.

In the OnDataChangeEvent, use the EnumChildWindows API function to "scout" out what the current form is, then check to see if the grid is "there" (hidden or not). If it is, Post a message to it or to the form controlling the grid to let it know the user has scrolled to a new record.

When the form (grid, etc) gets this message, process the BLOB field. With this method, if the form exists (with the grid on it) then fine, stuff happens. If the grid does not exist then nothing happens because the EnumChildWindows function did not locate the grid.

Now that you have the longer  (and more processor-intensive) answer I'll offer a shorter one:

In the OnDataChange event, simply post a message (user-defined) to the application which all windows will receive. When your grid gets the message, process the BLOB. All of the other windows in the app will ignore the message since they have no way of processing it.

Hope this helps & good luck with your project!
Pegasus
0
 

Author Comment

by:ChrisBerry
ID: 1346150
Hi Pegusus,

Thanks, just what I wanted. I did not think this was the solution as I was not changing data in the record.

Regards
Chris
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

Title # Comments Views Activity
Using FastMM4... should I enable MMX option? 9 76
Delphi Form ownership 4 73
HTML text in the body of an email (delphi code) 12 96
How to debug For loops? 3 46
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

17 Experts available now in Live!

Get 1:1 Help Now