Results 1 to 3 of 3

Thread: How to maintain scroll position in DataGridView after updating and refilling datagrid

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    19

    Question How to maintain scroll position in DataGridView after updating and refilling datagrid

    Hello,

    I was wondering if there is a way to keep the scroll position in a datagridview on a windows application after updating a record and refreshing the datagridview.

    i am working with vb.net 2005. i have some textboxes where I load the corresponding fields from the datagridview. then the user is able to update the fields in the textboxes and then click on the update button whrere an update storeprocedure is executed and the I refill the datagridview to reflect the changes made. but I want to be able to maintain the scroll position in the same position and not going all the way to the top as it is doing rightnow.


    This is how i am Re-Filling my datagridview:
    Me.ClientsTableAdapter.Fill(Me.ACHReaderDataSetTblClients.Clients)


    thanks for any suggestion, or example.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to maintain scroll position in DataGridView after updating and refilling datagrid

    That is extremely wasteful. There's no need for you to be getting all your data again. All you need to do is assign the new data to the row of your DataTable and call AcceptChanges. All the other data is untouched so there's no need to throw it all away only to retrieve it again.

    Having said that, you normally wouldn't be saving one row at a time either. You'd normally let the user make all the changes first and then save them as a batch.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    19

    Smile Re: How to maintain scroll position in DataGridView after updating and refilling datagrid

    Hello thanks for your suggestion, please let me know how to assign the new data to the row of the DataTable and call AcceptChanges. Can you provide an example.

    Thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width