There is an example of how to modify SortableBindingList to use a stable sort. However, there is an updated version of SortableBindingList. What is the best way to modify this new version to use a stable sort? I think I would want a flag on the SortableBindingList to let the user of the SortableBindingList decide if they want to use (slower) stable sort or (faster) default sort.
Thanks
You can solve this problem by writing a stable sort extension method for
List<T>:and then in the new version of
SortableBindingListchange this line:to:
This works by using the unstable sort supplemented with a secondary key on the item index within the list. Since this version doesn’t use the pathologically slow insertion sort to achieve a stable sort, it should be fast enough for general use.