Vb.net 滚动至Datagridview选定行

Vb.net 滚动至Datagridview选定行,vb.net,winforms,search,datagridview,row,Vb.net,Winforms,Search,Datagridview,Row,我已经做了相当多的寻找这个答案,但没有人能够帮助我。自从其他网站建议使用.Focus()以来,我一直试图使用它,甚至想看看它是否适用,但事实并非如此。我只想要DataGridView,HistoryData 跳转到选定的行。它当然会这样做,但当足够的项目填满网格时,它不会滚动到它。网格上是否有我丢失的参数 这是我的密码: Private Sub HistorySearch_TextChanged(sender As Object, e As EventArgs) Handles Hist

我已经做了相当多的寻找这个答案,但没有人能够帮助我。自从其他网站建议使用
.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
Private Sub HistorySearch\u TextChanged(发送者作为对象,e作为事件参数)处理HistorySearch.TextChanged
尝试
如果HistorySearch.Text.ToString为“”,则
对于HistoryData.Rows中作为DataGridViewRow的每个HistoryRow
HistoryData.ClearSelection()
对于HistoryRow.Cells中作为DataGridViewCell的每个HistoryCell
如果HistoryCell.Value.ToString.StartsWith(HistorySearch.Text.ToString)则
HistoryRow.Selected=True
Dim i作为整数=HistoryData.CurrentRow.Index()
其他的
HistoryRow.Selected=False
如果结束
如果HistoryCell.Value.ToString.Contains(HistorySearch.Text.ToString)则
HistoryRow.Selected=True
Dim i作为整数=HistoryData.CurrentRow.Index()
返回
其他的
HistoryRow.Selected=False
如果结束
下一个
下一个
如果结束
特例
MsgBox(例如消息)
结束尝试
端接头

如果我正确理解您的问题,您可以使用以下任一选项滚动到
DataGridView
中的特定行:

CurrentCell

如果设置了
DataGridView
的值,它将选择指定的单元格并滚动以使该单元格可见

例如,选择最后一行并滚动到该行:

“使用合适的索引,10只是一个例子
DataGridView1.CurrentCell=DataGridView1.Rows(10)。Cells(0)
FirstDisplayedScrollingRowIndex

您也可以设置为滚动到特定行,但它不会选择该行:

例如,仅滚动到第10行:

“使用合适的索引,10只是一个例子
DataGridView1.FirstDisplayedScrollingRowIndex=10
关于解决方案#1,如果单元格(0)不可见怎么办?它引发了一个异常,我需要在单元格上循环,并用visible=true检查第一个单元格