Scroll to Select Datagridview Row

I searched quite a lot for this answer, but no one was able to help me. I tried to use or even see if applicable .Focus(), as other websites suggested it, but it is not. I would just like DataGridViewHistoryData.

to go to the selected line. This, of course, is true, but he will not scroll it when the number of elements fills the grid. Could there be a parameter that is missing in the grid?

Here is my code:

    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
+4
source share
1 answer

If I understand your question correctly, you can scroll to a specific line in DataGridViewusing any of these options:

Currentcell

CurrentCell DataGridView, , .

, :

'use suitable index, 10 is just for example
DataGridView1.CurrentCell = dataGridView1.Rows(10).Cells(0)

FirstDisplayedScrollingRowIndex

FirstDisplayedScrollingRowIndex , :

, 10- :

'use suitable index, 10 is just for example
DataGridView1.FirstDisplayedScrollingRowIndex = 10
+3

Source: https://habr.com/ru/post/1599421/


All Articles