I've got a DataGridView and I want to cycle through each row that begins with the letter key that is pressed.
In other words, if I have a list like this:
Alpha
Baker
Beta
Bravo
Charlie
Delta
The first time I pres the "B" key, the "Baker" row is selected. If I hit the "B" key again, the "Beta" row is selected. If the current row is "Bravo", pressing "B" will take me back up to the "Baker" row.
So far, I've only figured out how to jump to the first row using this code:
Any have an idea as to how I can jump to the next item on each key press?
In other words, if I have a list like this:
Alpha
Baker
Beta
Bravo
Charlie
Delta
The first time I pres the "B" key, the "Baker" row is selected. If I hit the "B" key again, the "Beta" row is selected. If the current row is "Bravo", pressing "B" will take me back up to the "Baker" row.
So far, I've only figured out how to jump to the first row using this code:
Code:
Private Sub JumpToRow(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles dgvServiceList.KeyPress
strKeyChar = UCase(e.KeyChar)
If Char.IsLetter(strKeyChar) Then
For Each row As DataGridViewRow In dgvServiceList.Rows
If UCase(row.Cells(0).Value.ToString.StartsWith(strKeyChar)) Then
dgvServiceList.CurrentCell = dgvServiceList.Item(0, row.Index)
Exit For
End If
Next
End If
End Sub
Any have an idea as to how I can jump to the next item on each key press?