1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Dim row As Integer
Dim column As Integer
Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Enter Then
' Lorsque l'on valide une cellule en mode NON édition, on passe à la cellule suivante sur la même ligne,
' ou à la 1ère cellule de la ligne suivante si la cellule est la dernière de la ligne en cours.
' Avec création d'une nouvelle ligne si cette ligne est la dernière.
row = DataGridView1.CurrentCell.RowIndex
column = DataGridView1.CurrentCell.ColumnIndex
column += 1
If column = DataGridView1.ColumnCount Then
row += 1
If row = DataGridView1.Rows.Count Then
If row = DataGridView1.RowCount Then
If DataGridView1.DataSource IsNot Nothing Then
bindingSource1.AddNew()
Else
DataGridView1.Rows.Add()
End If
End If
End If
column = 0
End If
DataGridView1.CurrentCell = DataGridView1.Rows(row).Cells(column)
' Arrivant en fin de ligne, par defaut Enter crée une nouvelle ligne, mais vu qu'elle a déjà été
' créée par programmation, nous indiquons que l'événement a été géré.
e.Handled = True
End If
End Sub |
Partager