Hi
I have a DGV With 12 column, the columns 6-12 are only for information hence set to readonly..
What i was looking for is when the user press Enter key in columns 1 to 5, if the cell data Validates then next cell in same row should be selected, after col5 the Enter key should set the focus to next row col1.
After Googling i was able to partially achieve the requirement,
The problem is when the dgv is in edit mode and enter key is pressed in col5, then col6 of same row is being selected.
I have a hint of adding a handle to EditingControl and handling the KeyDown Event, but KeyDown event of EditingControl is being fired first after then cellvalidating of the DGV, hence cant set the focus to next cell before cell validating
kindly help to achieve this,
Regads
TIA
What I have tried:
<pre>Public Class mydgv
Inherits DataGridView
Dim ResetCol As Integer = 4
Protected Overrides Function ProcessDialogKey(keyData As Keys) As Boolean
Dim key As Keys = keyData And Keys.KeyCode
If key = Keys.Enter Then
Return Me.ProcessTabKey(keyData)
End If
Return MyBase.ProcessDialogKey(keyData)
End Function
Protected Overrides Function ProcessDataGridViewKey(e As KeyEventArgs) As Boolean
If e.KeyCode = Keys.Enter Then
Dim currPos As New Point(0, 0)
Dim NextRowId As Integer = -1
If MyBase.CurrentCell IsNot Nothing Then currPos = New Point(MyBase.CurrentCell.RowIndex, MyBase.CurrentCell.ColumnIndex)
NextRowId = currPos.X
If currPos.Y >= Me.ResetCol Then
If NextRowId < Me.RowCount - 1 Then
NextRowId += 1
End If
MyBase.CurrentCell = MyBase.Rows(NextRowId).Cells(0)
Return True
Else
Return Me.ProcessTabKey(e.KeyData)
End If
End If
Return MyBase.ProcessDataGridViewKey(e)
End Function