Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Record Navigation using the DBGrid control

Posted on 1998-05-18
9
Medium Priority
?
534 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
[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
  • 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
Industry Leaders: 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!

 

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
 
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 200 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

Industry Leaders: 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

715 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