Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
I have one gridview and it contains no.of records. if i have scroll down for 50th or any other record then if i refresh the form through a button, i will lose my current positon and automatically comes to 1st record. I want the record at the same position say 50 even after refreshing. Please help me...
Thanks in advance.
Posted 13-Dec-12 23:10pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I use the DataGridView's FirstDisplayedScrollingRowIndex Property[^]
Like this: (my DataGridView is named gvMast)
'Variable to save the scrolling index with
    Private intSaveScrollingIndex As Integer = 0
    'When user scrolls the grid, save the index
    Private Sub gvMast_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles gvMast.Scroll
        intSaveScrollingIndex = gvMast.FirstDisplayedScrollingRowIndex
    End Sub
    'When the grid is refreshed, scroll the grid back to the proper place if possible
    Private Sub LoadGrid()
        ' *** Whatever code you have that reloads/refreshed your grid goes here *** '

        'If filters or changes have removed rows to scroll to, or have removed ALL rows, reset the scrolling index to zero
        If gvMast.Rows.Count <= intSaveScrollingIndex _
        OrElse intSaveScrollingIndex = -1 Then
            intSaveScrollingIndex = 0
        End If
        'Only set scrolling index when there are rows to display
        If gvMast.Rows.Count > 0 Then
            gvMast.FirstDisplayedScrollingRowIndex = intSaveScrollingIndex
        End If
    End Sub
aktharulameen at 17-Dec-12 1:31am
Hi Kschuler, The above gridview's property FirstDisplayedScrollingRowIndex is worked fine for me. Thank you so much to give me the best solution. Once again thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Shai Vashdi 540
1 Tadit Dash 305
2 Sergey Alexandrovich Kryukov 250
3 Peter Leow 190
4 OriginalGriff 148
0 Sergey Alexandrovich Kryukov 9,395
1 OriginalGriff 5,473
2 Peter Leow 4,150
3 Maciej Los 3,540
4 Abhinav S 3,333

Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid