我已经搜索了很多关于这个问题的答案,但都没有能够帮助我。我尝试使用或查看.Focus()
是否适用,因为其他网站建议这样做,但不是这样。我只希望DataGridView
,HistoryData.
跳到所选行。当足够的项填满网格时,它当然会跳转,但不会滚动到该行。网格上可能有我遗漏的参数吗?
下面是我的代码:
Private Sub HistorySearch_TextChanged(sender As Object, e As EventArgs) Handles HistorySearch.TextChanged
Try
If HistorySearch.Text.ToString <> "" Then
For Each HistoryRow As DataGridViewRow In HistoryData.Rows
HistoryData.ClearSelection()
For Each HistoryCell As DataGridViewCell In HistoryRow.Cells
If HistoryCell.Value.ToString.StartsWith(HistorySearch.Text.ToString) Then
HistoryRow.Selected = True
Dim i As Integer = HistoryData.CurrentRow.Index()
Else
HistoryRow.Selected = False
End If
If HistoryCell.Value.ToString.Contains(HistorySearch.Text.ToString) Then
HistoryRow.Selected = True
Dim i As Integer = HistoryData.CurrentRow.Index()
Return
Else
HistoryRow.Selected = False
End If
Next
Next
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub