这应该可以解决问题
Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
Dim iCol = DataGridView1.CurrentCell.ColumnIndex
Dim iRow = DataGridView1.CurrentCell.RowIndex
If iCol = DataGridView1.Columns.Count - 1 Then
If iRow < DataGridView1.Rows.Count - 1 Then
DataGridView1.CurrentCell = DataGridView1(0, iRow + 1)
End If
Else
DataGridView1.CurrentCell = DataGridView1(iCol + 1, iRow)
End If
End If
End Sub
这将解决提到的“编辑”问题。
Private Sub DataGridView1_CellEndEdit(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Dim iCol = DataGridView1.CurrentCell.ColumnIndex
Dim iRow = DataGridView1.CurrentCell.RowIndex
If iCol = DataGridView1.Columns.Count - 1 Then
If iRow < DataGridView1.Rows.Count - 1 Then
DataGridView1.CurrentCell = DataGridView1(0, iRow + 1)
End If
Else
If iRow < DataGridView1.Rows.Count - 1 Then
SendKeys.Send("{up}")
End If
DataGridView1.CurrentCell = DataGridView1(iCol + 1, iRow)
End If
End Sub