Scrolling DataGrid's selected row out of view selects next control

B

Brian Tkatch

I have a form with two DataGrids, which are kept in sync manually via
Stored PROCEDURE calls. That is, when a record is selected on the first
grid, a stored PROCEDURE is CALLed to Fill() the next second DataGrid's
DataSource. All that works very well. And, when there are no records to
display, it is simply left blank.

My issue is that when i scroll the first one, sometimes the second grid
shows a bunch of null values (a "new" record).

After a little study, i realized the problem happens when there are no
records to show in the second grid, and the first grid is scrolled so
that the currently selected row (as indictated by Black Right-Pointing
Pointer (as Charmap calls it)) goes off the screen. This causes the
second grid to be automatically selected (as the now showing Black
Right-Pointing Pointer indicates) but because there are no records, it
starts a new one.

This is the same issue as having a blank DataGrid as the first control
in a Form's TabIndex. It will start a new record immediately.

The question is, how do i prevent this from happening? Starting a new
record needs to be possible manually, it should just not be started
automatically. And i would like the keep eacdh grid as a TabStop, and
lkeep the current order of TabIndexing.

B.
 
B

Brian Tkatch

Kerry said:

Much appreciated.

That actually was not what i wanted. But it got me thinking. :)

Since the scroll is making the first grid to lose focus....

In the scroll even of the DataGrid i added "sender.Select()". This
returns focus to the DataGrid which removes the "new" record from the
following grid.

Unfortunately, the other DataGrid does get Focus for a second and the
nulls are sometimes seen.

B.
 
B

Brian Tkatch

Brian said:
Much appreciated.

That actually was not what i wanted. But it got me thinking. :)

Since the scroll is making the first grid to lose focus....

In the scroll even of the DataGrid i added "sender.Select()". This
returns focus to the DataGrid which removes the "new" record from the
following grid.

Unfortunately, the other DataGrid does get Focus for a second and the
nulls are sometimes seen.

B.

OK, i think i got what i wanted.

1) Add a class-wide boolean variable:

Dim Scrolling As Boolean

2) In the Scroll event of the DataGrid set it:

Scrolling = True

3) In the Validating event of the DataGrid, if it is set, unset it and
cancel the event.

If Scrolling Then
Scrolling = False
e.Cancel = True
End If

The only issue right now, is that if the first thing done when it comes
up is a scroll (that is, the user scroll before effecting any other
event), it still shows the null record the first time it is passed
(even if the user scrolls many times).

B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top