Sorting a SortedBindingList

Sorting a SortedBindingList

Old forum URL: forums.lhotka.net/forums/t/3596.aspx


dgoldin posted on Wednesday, September 26, 2007

Hello,

I have a small question concerning sorting a SortedBindingList using the mechanisms the WPF CollectionView offers.
I try to sort it with the following "official" approach:

ICollectionView cv = CollectionViewSource.GetDefaultView(_poiList.ItemsSource);                      

SortedBindingList<PointOfInterest> sbl = (SortedBindingList<PointOfInterest>)_poiList.ItemsSource;
sbl.ApplySort(sortBy, direction);

cv.Refresh();  

Unluckily it has no effect at all.
Is there a different way of doing this using WPF mechanisms without calling ApplySort() on the list directly (this is actually my current workaround, but not very elegant since I do grouping using GroupDescriptions)?

The CollectionView Refresh() method calls on RefreshOverride of the BindingListCollectionView method, which in turn calls on ConvertSortDescriptionCollection, also contained in the BindingListCollectionView class, which does the following:

ITypedList internalList = this.InternalList as ITypedList;
if (internalList != null) {
// more conditions and somewhen a call an ApplySort()
}


Any idea why it checks whether the list implements ITypedList? As far as I understand its not relevant for sorting but for DataBinding itself. The MSDN documentation for ITypedList states that one either needs to implement a ITypedList or to use a strongly typed Item in the List which is given by the use of generics if I understand correctly.

Is this a known issue? Why does SortedBindingList does not implement ITypedList?

Thanks a lot in advance,
    Dimitri

Copyright (c) Marimer LLC