I\'m using a DataGridView in my WinForms application. My main objective is to make the Enter key not move to the next row in the grid. I still want the enter key to validate
thanks for the solution. my version is a slight different from yours, because when i move to the other cell, and my code returns e.cancel=false in the cell validating event, an error will be generated, says that: "operation did not succeed, because the program cannot commit or quit a cell value change". so i put try catch to overcome this problem.
this is my code:
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
Dim key As Keys = (keyData And Keys.KeyCode)
If key = Keys.Enter Then
If MyBase.CurrentCell.ColumnIndex = 1 Then
Dim iRow As Integer = MyBase.CurrentCell.RowIndex
MyBase.EndEdit()
Try
MyBase.CurrentCell = Nothing
MyBase.CurrentCell = MyBase.Rows(iRow).Cells(1)
frmFilter.cmdOk_Click(Me, New EventArgs)
Catch ex As Exception
End Try
Return True
End If
End If
Return MyBase.ProcessDialogKey(keyData)
End Function