I have a xamDataGrid which is populated using a Dataset. I have a situation where I need to refresh the data (by setting the Datasource = null, update the data in the dataset and set the Datasource to the dataset again). My customer now whishes that the row selected before the refresh should als be selected after the refresh. How can this be done?
Perhaps someone has solved a similar problem already.
Thank you in advance for any help
Markus
Hi Vlad
Thanks for you help. I implemented a simple solution based on you post. Below my code fragment (for other users with the same problem)
Best Regards
int ActiveRecordIdx = -1;DataRecord ActiveRecord = xamMainDataGrid.ActiveRecord as DataRecord;if (ActiveRecord != null){ ActiveRecordIdx = ActiveRecord.Index;}
// Do data refresh here
if (ActiveRecordIdx >= 0 && ActiveRecordIdx < xamMainDataGrid.Records.Count) { xamMainDataGrid.Records[ActiveRecordIdx].IsActive = true; xamMainDataGrid.BringRecordIntoView(xamMainDataGrid.Records[ActiveRecordIdx]); }
There are couple of ways to do this. You can store the index of the last selected record in a custom integer variable and then use the Records collection to resolve the selected record after rebinding e.g.:
xdg1.Records[index].IsSelected=true;
In addition, the grid exposes a SelectedItem.Records collection that can be used to add/remove records programatically and SelectedItemsChanging/ed events that might be helpfull in determine the current selected records in the grid.
Let me know if you have any questions with this matter.