Datagrid and scrolling

  • Thread starter Thread starter Stan Guss
  • Start date Start date
S

Stan Guss

My question concerns navigation with the DataGrid on my
Windows Form.

Private Sub btnNext_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnNext.Click
' Move to the next record
NextRecord()
' Highlight the entire row for user feedback.
grdXNew.Select(grdXNew.CurrentCell.RowNumber)

End Sub


' Move the BindingContext Position to the next record.
Public Sub NextRecord()
' The position of the binding context controls
the "current record"
Me.BindingContext(dtXNew).Position += 1
End Sub

The code seems to work fine, except that after
GrdXNew.Select is fired, the Datagrid scrolls back to the
first record. The row that was navigated to is selected,
but if it is not within the bounds of the grid, the row is
not viewable. The user would then have to scroll the
Datagrid to see what row is highlighted. It appears the
behavior is that the grid always scrolls to the top after
a selection is made programmatically.

My question is: Is there a way to maintain the highlighted
row in the viewable area of the grid?

Thank you in advance.
 
Back
Top