滚动到Datagridview选择Row

时间:2015-07-23 23:47:46

标签: vb.net winforms search datagridview row

我已经做了很多寻找这个答案,但没有人能够帮助我。我试图使用甚至查看.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

0 个答案:

没有答案