Changing an item in a sorted WPF ListView does not change the sorting position of this item

I have a sortable list that is populated with current data as it appears. Sorting works fine, but the real problem occurs when an item changes after being added to the collection. The position of the changed item does not change regardless of the sort order.

I have googled, but I could not find a better solution to make my list an excellent sorted list.

Solutions??

+4
source share
1 answer

I assume that you are following an approach similar to this sample MSDN . If so, then sorting is based on the sort type SortDescriptions. As long as source collection is observable, sort order should be followed when items are added or removed from the collection.

The real problem occurs when an item changes after being added to the collection. In this case, the collection will not be automatically re-sorted.

I explain in detail the problem in 'E' for the editable collection (in my ItemsControl from A to Z ). I also present several workarounds that offer different levels of performance. The sharpest is to force the entire collection to re-sort by calling Refresh () on the CollectionView. If possible, I would avoid this and use a better option, for example, implementing IEditableObject for your elements and issuing Edit (), followed by Commit () when the properties change in the element.

+4
source

Source: https://habr.com/ru/post/1301196/


All Articles