Solved

Record Navigation using the DBGrid control

Posted on 1998-05-18
9
472 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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