Datagridview reselect a previosly selected row after refresh()
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Datagridview reselect a previosly selected row after refresh()

  1. #1
    Join Date
    May 2014
    Posts
    1

    Datagridview reselect a previosly selected row after refresh()

    Question is how to have it so that the last selected row is reselected again after the refresh... something

    string currentlySelected = VersionsGridView.SelectedRows[0].Cells[1].Value.ToString());

    VersionsGridView.DataSource = Versions.CreateSource();

    VersionsGridView.EndEdit();

    VersionsGridView.Refresh();



    the RowIndex for the "currentlySelected" should be the same as the datasource file contents don't change, but incase it did how to have it search for the 'currentlySelected ' value and reselect it again if it finds it in the rows?

    Thanks

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,370

    Re: Datagridview reselect a previosly selected row after refresh()

    Save the value of the primary key (e.g. the row id) before refreshing. After the refresh, find the row with the matching id and select it.

  3. #3

    Re: Datagridview reselect a previosly selected row after refresh()

    if there are too many rows to search using primary key value, you can store the row index and simply select it back, if it would not have changed immediately after Refresh (it would change in case of a deleted row or table changed).

    Doing a refresh itself is costly, so a primary value check would be the best way to go as the mod Arjay has said.
    --
    BossMode

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center