Click here to Skip to main content
12,998,892 members (66,911 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100