Joined: 28 Feb 2005
|Posted: Wed Jul 20, 2011 1:26 am Post subject: Sorting support using SortableBindingList
|If you bind Virtual Tree to a collection that supports the standard ITypedList interface then Virtual Tree can automatically implement sorting (so that when you click on a column header the tree is sorted via that column). The ITypedList interface is implemented by DataSets and Infralutions Virtual Data Objects collections - allowing you to get sorting support for these collections with no coding effort. But what if you just want to be able to sort a simple object list?
The Infralution.Common assembly defines a SortableBindingList<> class that implements the ITypedList interface for a simple object collection. So instead of using List<> or BindingList<> you would implement your collections using SortableBindingList<>.
There is one more step you need to take to get sorting working. For sorting to work Virtual Tree needs to bind to data via the ITypedList interface rather binding directly to the object properties via reflection. So instead of setting the TypeName property in the RowBinding, you must set the TypedListName property to the name of the TypedList. For SortableBindingList the TypedListName property just needs to be set to the simple class name of the contained objects.
For example if you had a list of the class "Part"
|private SortableBindingList<Part> _parts = new SortableBindingList<Part>(); |
Then the TypedListName property should be set to "Part" and the TypeName property should be blank.