小编Jes*_*mes的帖子

滚动到Datagridview选定的行

我已经做了很多寻找此答案的工作,但没有一个能够帮助我。.Focus()自其他网站建议以来,我尝试使用甚至查看是否适用,但事实并非如此。我只想要DataGridViewHistoryData。

跳到所选行。它当然会这样做,但是当有足够的项目填充网格时,它不会滚动到它。网格上可能缺少一个参数吗?

这是我的代码:

    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 …
Run Code Online (Sandbox Code Playgroud)

vb.net search datagridview row winforms

5
推荐指数
1
解决办法
9474
查看次数

标签 统计

datagridview ×1

row ×1

search ×1

vb.net ×1

winforms ×1