Record Navigation using the DBGrid control

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?
ChrisBerryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JimBob091197Commented:
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
ZifNabCommented:
Hi,

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

Regards, ZiF.
0
ZifNabCommented:
Forget something... you find OnDataChange event on TDataSource... and I meant Well I was thinking on the ondatachange event....
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

ChrisBerryAuthor Commented:
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
JimBob091197Commented:
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
kjtengCommented:
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
ChrisBerryAuthor Commented:
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
Pegasus100397Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChrisBerryAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.