Scroll to Datagridview selected Row

Jesse James

I've done quite a bit of searching for this answer but none have been able to help me. I've attempted to use or even see if .Focus()was applicable since other websites suggested it, but it is not. I would just like the DataGridView, HistoryData.

to jump to the selected row. It of course does so but it will not scroll to it when enough items fill the grid. Could there be a parameter i'm missing on the grid?

Here's 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
Reza Aghaei

If I understand your question correctly, You can scroll to specific row in DataGridView using either of these options:

CurrentCell

If you set the CurrentCell of DataGridView it selects the specified cell and scrolls to make the cell visible.

For example to select the last row and scroll to it:

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

FirstDisplayedScrollingRowIndex

You can also set FirstDisplayedScrollingRowIndex to scroll to a specific row, but it doesn't select the row:

For example to only scroll to the 10th row:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Scroll to Datagridview selected Row

From Dev

Retrieving selected row in dataGridView as an object

From Dev

Retrieving selected row in dataGridView as an object

From Dev

Kendo Grid scroll to selected row

From Dev

Scroll to selected row correctly for JTable

From Dev

vb.net datagridview not showing selected row

From Dev

Datagridview how to cast selected row to custom object

From Dev

DataGridView- How to jump to the selected row in search?

From Dev

DataGridView selected row to display in text boxes

From Dev

print selected row from datagridview Error

From Dev

Datagridview how to cast selected row to custom object

From Dev

How to check if have any row selected on DataGridView?

From Dev

how to delete selected row from datagridview

From Dev

How to delete selected row from datagridview and database?

From Dev

Show DataGridView's first row (scroll up to first row)

From Dev

DataGridView row text disappears on every row except the selected one

From Dev

How to delete last row in DataGridView and keep the row selected?

From Dev

DataGridView row text disappears on every row except the selected one

From Dev

When selecting all cells in a row of datagridview, set the row to selected as property

From Dev

When the last row in a DataGridView is selected, a value from the previous row is returned instead of from the selected row

From Dev

When the last row in a DataGridView is selected, a value from the previous row is returned instead of from the selected row

From Dev

Winforms - Position new form directly under Datagridview selected row of parent

From Dev

Datagridview correct row is selected but the arrow is still pointing at the first record

From Dev

Need to get the first cells of a selected row in datagridview before delete it

From Dev

C# DataGridView get selected row number Exception

From Dev

Trying to delete selected row from datagridview but it is deleting multiple rows

From Dev

How to change row color in datagridview after checkbox is selected

From Dev

How to update selected row in datagridview through textbox located on another form?

From Dev

C# DataGridView get selected row number Exception

Related Related

  1. 1

    Scroll to Datagridview selected Row

  2. 2

    Retrieving selected row in dataGridView as an object

  3. 3

    Retrieving selected row in dataGridView as an object

  4. 4

    Kendo Grid scroll to selected row

  5. 5

    Scroll to selected row correctly for JTable

  6. 6

    vb.net datagridview not showing selected row

  7. 7

    Datagridview how to cast selected row to custom object

  8. 8

    DataGridView- How to jump to the selected row in search?

  9. 9

    DataGridView selected row to display in text boxes

  10. 10

    print selected row from datagridview Error

  11. 11

    Datagridview how to cast selected row to custom object

  12. 12

    How to check if have any row selected on DataGridView?

  13. 13

    how to delete selected row from datagridview

  14. 14

    How to delete selected row from datagridview and database?

  15. 15

    Show DataGridView's first row (scroll up to first row)

  16. 16

    DataGridView row text disappears on every row except the selected one

  17. 17

    How to delete last row in DataGridView and keep the row selected?

  18. 18

    DataGridView row text disappears on every row except the selected one

  19. 19

    When selecting all cells in a row of datagridview, set the row to selected as property

  20. 20

    When the last row in a DataGridView is selected, a value from the previous row is returned instead of from the selected row

  21. 21

    When the last row in a DataGridView is selected, a value from the previous row is returned instead of from the selected row

  22. 22

    Winforms - Position new form directly under Datagridview selected row of parent

  23. 23

    Datagridview correct row is selected but the arrow is still pointing at the first record

  24. 24

    Need to get the first cells of a selected row in datagridview before delete it

  25. 25

    C# DataGridView get selected row number Exception

  26. 26

    Trying to delete selected row from datagridview but it is deleting multiple rows

  27. 27

    How to change row color in datagridview after checkbox is selected

  28. 28

    How to update selected row in datagridview through textbox located on another form?

  29. 29

    C# DataGridView get selected row number Exception

HotTag

Archive