-
May 11th, 2014, 01:13 PM
#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
-
May 11th, 2014, 09:52 PM
#2
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.
-
May 20th, 2014, 08:25 PM
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|