我正在尝试遍历 datagridview 行,其中单元格值以用户按下的相同 keychar 开头。下面的代码有效,但是当我第二次、第三次按下相同的字母时,它不会将选择移动到以相同字母开头的下一行...
Private Sub dataGridView1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles dgw.KeyPress
If [Char].IsLetter(e.KeyChar) Then
For i As Integer = 0 To (dgw.Rows.Count) - 1
If dgw.Rows(i).Cells(1).Value.ToString().StartsWith(e.KeyChar.ToString(), True, CultureInfo.InvariantCulture) Then
If lastKey = e.KeyChar And lastIndex < i Then
Continue For
End If
lastKey = e.KeyChar
lastIndex = i
dgw.Rows(i).Cells(1).Selected = True
Return
End If
Next
End If
End Sub