22-10-23, 08:22 PM
كود :
Private selectedRowIndex As Integer = 0
Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown
' Handle the Up and Down keys
If e.KeyCode = Keys.Up Then
' Move the selection up
selectedRowIndex -= 1
ElseIf e.KeyCode = Keys.Down Then
' Move the selection down
selectedRowIndex += 1
End If
' Ensure the selected row index stays within valid bounds
If selectedRowIndex < 0 Then
selectedRowIndex = 0
ElseIf selectedRowIndex >= DataGridView1.Rows.Count Then
selectedRowIndex = DataGridView1.Rows.Count - 1
End If
' Select the new row
DataGridView1.CurrentCell = DataGridView1.Rows(selectedRowIndex).Cells(0)
End Sub
