Update to SortableBindingList

I’ve been a using this implementation of the SortableBindingList by Tim Van Wassenhove for a few years now but recently I noticed that although making a change to the list updated all bound controls it did not update the backing collection.

I switched back to a standard BindingList<T> in an attempt to resolve the issue and was surprised to find that it worked!

I found the only difference was that Tim’s implementation had a constructor that took an IEnumerable<T> where the System.ComponentModel implementation uses a List<T>  – like so

Incorrect
public SortableBindingList(IEnumerable<T> enumeration) : base(new List<T>(enumeration))

Correct
public SortableBindingList(IList<T> list): base(list)

Changing the constructor on Tim’s implementation to one that takes a list fixes the issue. This can be verified by taking a look at at least one other implementation of the SortableBindingList.

Posted in Articles and tagged , , , , .