Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
XamDataGrid Sorting and Grouping ICollectionView using MVVM
posted

I'm binding a XamDataGrid DataSource to the ICollectionView of an ObservableCollection in my ViewModel. When I remove the CurrentItem of the ICollectionView from the ObservableCollection in the ViewModel, I would like the CurrentItem to select the next object in the ObservableCollection as it appears to the user. If the user performs sorting or grouping on the XamDataGrid, the selection appears to jump around randomly when I remove the CurrentItem from the ObservableCollection, because the "next" item of the ObservableCollection corresponds to the order in which the objects were added to the ObservableCollection, not the order the objects are rendered on the screen inside the XamDataGrid (because of sorting and / or grouping).

I've tried subscribing to my XamDataGrid's Sorting and Grouping events, and populating the ICollectionView's SortDescriptions and GroupDescriptions properties in the event handlers, which seems to synchronize the XamDataGrid with the ObservableCollection, but this seems like it shouldn't be necessary.

Is the XamDataGrid capable of populating my ICollectionView SortDescriptions and GroupDescriptions properties directly, without the need for subscribing to these events? Is there another way of "synchronizing" the order of objects in my ObservableCollection?

Parents
No Data
Reply
  • 138253
    Offline posted

    Hello,

     

    It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking through your post and it seems like that the ICollectionView doesn’t synchronize with the XamDataGrid’s SortDescriptions and GroupByDescriptions. If you want you can explicitly add the Descriptions from the XamDataGrid to the ColectionView on Grouped and Sorted events.

     

    Feel free to write me if you have further questions.

Children