Private EditRow As Integer = -1
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
EditRow = DataGridView1.CurrentRow.Index
End Sub
Private Sub DataGridView1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Return Then
If DataGridView1.CurrentRow.Index < DataGridView1.RowCount - 1 AndAlso _
DataGridView1.CurrentCell.ColumnIndex = DataGridView1.ColumnCount - 1 Then
DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.CurrentRow.Index + 1)
Else
Dim cur_cell As DataGridViewCell = DataGridView1.CurrentCell
Dim col As Integer = cur_cell.ColumnIndex
col = (col + 1) Mod DataGridView1.Columns.Count
cur_cell = DataGridView1.CurrentRow.Cells(col)
DataGridView1.CurrentCell = cur_cell
End If
e.Handled = True
End If
End Sub
Private flag_cell_edited As Boolean
Private currentRow As Integer
Private currentColumn As Integer
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
SendKeys.Send("{TAB}")
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
If EditRow >= 0 Then
Dim new_row As Integer = EditRow
EditRow = -1
DataGridView1.CurrentCell = DataGridView1.Rows(new_row).Cells(DataGridView1.CurrentCell.ColumnIndex)
End If
End Sub