Vertical Scroll Bar out of sync in DataGrid

G

Gene Hubert

I'm assigning a new datasource (a datatable) to a datagrid that is
aready displayed in a form. Then I assign a new value to
CurrentRowIndex.

The datagrid always scrolls so that the new current row is visible.
However, the vertical scrollbar does not always adjust accordingly.

Upon the first instance of assigning a new datasource and setting the
currentrowindex to the _last_ record, the part of the vertical
scrollbar that can be dragged is happy to move correctly all the way
to the bottom. The newly set current row is visible at the bottom of
the grid.

If I then immediately invoke an instance of assigning a new datasource
and setting the currentrowindex to the _first_ record, the part of the
vertical scrollbar that can be dragged stays stuck all the way at the
bottom. The newly set current row is correctly visible at the top of
the grid.

I've tried various things with datagraid.VertScrollBar.Update(),
datagrid.Invalidate(Me.VertScrollBar.Region) and datagrid.refresh to
no avail.

The above sequence is part of a custom sort operation and happens when
sorting a column ascending and then immediately sorting the same
column descending. The same row is moving to either first or last in
the grid depending on the direction of the sort.

Anyone heard of this or know how to fix it?

Thanks,
Gene H.
 
K

Ken Tucker [MVP]

Hi,

I created a column style that would adjust the row heights and had a
similar problem. My work around was to resize the grid. I decrease the
grid size by 1 pixel and brought it back to the orginal size. The
scrollbars started to work again. Change is small enough the user wont see
the change.

Ken
------------------
I'm assigning a new datasource (a datatable) to a datagrid that is
aready displayed in a form. Then I assign a new value to
CurrentRowIndex.

The datagrid always scrolls so that the new current row is visible.
However, the vertical scrollbar does not always adjust accordingly.

Upon the first instance of assigning a new datasource and setting the
currentrowindex to the _last_ record, the part of the vertical
scrollbar that can be dragged is happy to move correctly all the way
to the bottom. The newly set current row is visible at the bottom of
the grid.

If I then immediately invoke an instance of assigning a new datasource
and setting the currentrowindex to the _first_ record, the part of the
vertical scrollbar that can be dragged stays stuck all the way at the
bottom. The newly set current row is correctly visible at the top of
the grid.

I've tried various things with datagraid.VertScrollBar.Update(),
datagrid.Invalidate(Me.VertScrollBar.Region) and datagrid.refresh to
no avail.

The above sequence is part of a custom sort operation and happens when
sorting a column ascending and then immediately sorting the same
column descending. The same row is moving to either first or last in
the grid depending on the direction of the sort.

Anyone heard of this or know how to fix it?

Thanks,
Gene H.
 

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

Similar Threads


Top