Hi @dopen oinam ,
You can try to override ProcessCmdKey method to replace datagridview keydown event to move the cell focus correctly.
Code:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = Keys.Enter Then
'check for last row
If DataGridView1.CurrentCell.RowIndex = DataGridView1.Rows.Count - 1 Then
'if it's not the last cell, move to the next one
If DataGridView1.CurrentCell.ColumnIndex <> DataGridView1.ColumnCount - 1 Then
DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(DataGridView1.CurrentCell.ColumnIndex + 1)
Else
' if last cell then either enter new raw or move to first cell.
'move to first column in new row
DataGridView1.Rows.Add(1)
DataGridView1.Refresh()
SendKeys.Send("{HOME}")
End If
Else
'if it's the last cell, move to the next row, first cell
If DataGridView1.CurrentCell.ColumnIndex = DataGridView1.ColumnCount - 1 Then
DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex + 1).Cells(0)
Else
'move to the next cell on the current row
DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(DataGridView1.CurrentCell.ColumnIndex + 1)
End If
End If
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = 5
DataGridView1.Columns(0).Name = "Product ID"
DataGridView1.Columns(1).Name = "Product Name"
DataGridView1.Columns(2).Name = "Product_Price"
DataGridView1.Columns(3).Name = "Product_Address"
DataGridView1.Columns(4).Name = "Product_Owner"
Dim row As String() = New String() {"1", "Product 1", "1000", "test1", "o1"}
DataGridView1.Rows.Add(row)
row = New String() {"2", "Product 2", "2000", "test2", "o2"}
DataGridView1.Rows.Add(row)
row = New String() {"3", "Product 3", "3000", "test3", "o3"}
DataGridView1.Rows.Add(row)
row = New String() {"4", "Product 4", "4000", "test4", "o4"}
DataGridView1.Rows.Add(row)
End Sub
Result: