I have a read only DGV on a tab 开发者_运维问答of my application. I let the users sort by column and reorder columns and select a row. In another part of the application you can edit the data that is in this dgv so when I go back to the tab with the dgv I'd like to refresh the data but keep the user's settings such as column order, sort order, and row selection. Right now I'm just setting the dgv to the new list of items and it resets all of these settings. Is there anyway to persist these after I rebind the data?
Thanks,
CodyStore the user's settings in some internal object. Wrap you binding logic in SuspendLayout() and ResumeLayout() calls, so that you can apply the settings back to the DGV before the the visuals are redrawn.
// pseudo code
private void RefreshDGV()
{
SaveUserSettings();
myDGV.SuspendLayout();
myDGV.DataSource = myDataSource;
ApplyUserSettings();
myDGV.ResumeLayout();
}
精彩评论