Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,
 
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
good
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
  Permalink  
Comments
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
0 OriginalGriff 383
1 Richard Deeming 180
2 ChauhanAjay 176
3 Sergey Alexandrovich Kryukov 171
4 Yogesh Kumar Tyagi 165
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2014
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