I have a scenerio where the user will select records in the datagrid and click a button which will refresh the datarid and add more records. When the user refreshes the datagrid I need to reselect the records. I was able to implement it using a converter to do this. When I click a record the selections are gone however once I scroll up and down ths datagrid the selections reappear. The converter is triggered when I scroll up and down the datagrid. Is there a way to stop the converter from reselecting on scrolling?
Attached is a sample project to demostrate
Hello,
Thank you for your post. I am not sure that using converter is the best approach. By default when you reset the data source property on the xamDataGrid to a different data source, all the previous Record instances get discarded and new ones get created. That's why simply saving the selected records and restoring them in the selected collection will not work. One way you can however do this is you can save some unique id's of the records that are selected and then after resetting the data source, find the records in the xamDataGrid with those id's and set their IsSelected property. This would effectively restore selected records.
Let me know if you need any further assistance on this matter.
The reason I was avioding that approach was because that will involve a foreach loop to find the records and select them. And there maybe times where there will be thousands of records which can take awhile to loop thru. Is there a good approach to do so without slowing down proformance?
Thank you for your feedback. I have tested my suggestion using your sample application( and I do not recognize any performance issue as I do not use nested loops.
I am attaching the modified version of your sample application(XamDataGridActiveItemModified.zip)
Please let me know if you have any other questions on this matter.
Thank you this index loop is better then looping thru all data.