Reputation: 2224
I have a datagrid bound to a list of items. I would like to be able to sort the grid by clicking the column headers. After the grid is sorted I would like to further organize it by drag reordering. My problem is that whenever there is a sort I'm unable to drag re-order items (the list is automatically re-sorted after the drop). Also as soon as an item is edited the grid is re-sorted. I've tried intercepting this in the sorting event, but the event isn't fired when the 'auto-sorting' takes place, only when the actual sort is applied to the view.
I've tried copying the sorted view to a new list and then setting the itemsource to the sorted list. The problem with this approach is that the sort direction doesn't toggle.
I've fooled around for several hours and decided I must be missing something obvious.
Upvotes: 0
Views: 471
Reputation: 17085
You will need to implement everything related to sort.
You need a command for data grid headers bound to your sort method. and the headers' text bound to direction of the current column sort
You need a sorted collection which is bound to items source of the data grid
You need an enum containing all the clickable columns so that when user clicks a column the sort method is called
You need to implement a sort method with these parameters: bool sortDirection
and SortByColumnEnum column
. which updates the sorted collection and therefore the data grid is changed.
After that you can reorder the items by changing their index inside the sorted collection.
Upvotes: 1