View previous topic :: View next topic |
Author |
Message |
Andrew Rowley
Joined: 24 Dec 2005 Posts: 63
|
Posted: Thu Nov 22, 2007 5:20 am Post subject: Sorting automatically |
|
|
In the documentation, it says "If your DataSource implements the ITypedList and IBindingList interfaces then the ObjectRowBinding class will handle sorting for you automatically."
I am finding it is not so straightforward
I am using Object binding and setting it up programatically.
If I have a class MyClass and a class SortableList<MyClass> that implements IBindingList and ITypedList, what properties do I need to specify for the ObjectRowBinding?
The SortableList is the root row, and the other objects are the data rows.
I am currently using version 2 - do I need verison 3 to handle the generics? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Nov 22, 2007 10:30 pm Post subject: |
|
|
While it should be possible to get Version 2 of Virtual Tree to bind properly to a generic list I would strongly recommend upgrading to Version 3 of Virtual Tree if you are using .NET 2.0 or later. Version 3 includes explicit support for generic types and other .NET features as well as a number of performance improvements.
See the following thread on the changes to ObjectBindings for generics (and possible workarounds for Version 2 which doesn't have these changes)
http://www.infralution.com/phpBB2/viewtopic.php?t=557
There are couple of things you have to get right for sorting using ITypedList to work properly:
First you must supply a RowBinding that binds to the root item (ie the DataSource). Note that if VirtualTree cannot find a binding for the root item it will still display items (if the DataSource supports IList) - however sorting via ITypedList will not work.
The best way to ensure that your RowBinding will bind to a generic type is probably to set the rowBinding.Type property programmatically eg
Code: | rowBindingSortableList.Type = typeof(SortableList<MyClass>); |
The ChildProperty for the root binding should be set to "this"
Secondly for the RowBinding you create for items in the list you should set the TypeListName property (not the TypeName or Type property). This should be set to the Name returned by ITypedList.GetListName(null). This means that Virtual Tree will use the ITypedList interface to retrieve information about the items (rather than using reflection). _________________ Infralution Support |
|
Back to top |
|
|
Andrew Rowley
Joined: 24 Dec 2005 Posts: 63
|
Posted: Fri Nov 23, 2007 9:05 am Post subject: |
|
|
Thanks, I have it working now. I have downloaded version 3, and will probably upgrade soon. |
|
Back to top |
|
|
|