Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

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?
0
ChrisBerry
Asked:
ChrisBerry
  • 3
  • 2
  • 2
  • +2
1 Solution
 
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
Technology Partners: 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!

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now