DataGridView - Scroll up/scroll down/keypress event?

dbtx

New member
Joined
Sep 18, 2006
Messages
2
Programming Experience
5-10
I have a DataGridView with FullRowSelect=True and ReadOnly=True. This is a Search Results-type view for which the user can select one of the rows which is to open a form with the details of that record.

The CellContentClick event works fine, but I would like the user to also have the ability to use the keyboard and scroll through the records and press enter when they find the appropriate record.

I have tried both the RowEntered event, and the KeyPress (and KeyUp) events to try and capture the movement through the rows. Neither one seems to be happening.

Is there something else I should be trying? Or do does anyone have any examples of things that they know works?
 
Using the arrow keys works fine here to navigate through cells. For Enter key you should capture the KeyDown event (because default Enter key selects next row), example:
VB.NET:
Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles DataGridView1.KeyDown
  If e.KeyCode = Keys.Enter Then
    MsgBox(DataGridView1.CurrentCell.FormattedValue)
    e.Handled = True
  End If
End Sub
 
That did work - although not initially. But something else must have been messed up, because after I deleted the control and recreated it, it then worked. Thanks.
 
Back
Top