Hi -
I am binding a collection of objects to a tree view having a view style of Outlook Express. The objects have a group name property, a name property and an ID property. I would like to use the group name as the root node and then have all other nodes with the same group name nested as child nodes.
I set the rootcolumnset proerty on the treeview to point at the autogenerated columnset. All I end up with is a flat list with no heirarchical display. Any ***ance is appreciated.
In the case where you are binding to a business object, the thing that makes a second level appear is a property of type IList, BindingList, etc., exposed by the object that the root level nodes represent. For example, let's say you had an object named 'Group', and you bind the tree to a BindingList<Group>:
public class Group{ public string Name { get; } public List<GroupMembers> Members { get; }}
public class GroupMembers{ public string Name { get; }}
Each Group object would have a collection of GroupMember objects, and you would see child nodes for each member of the Group object's Members collection.
The OutlookExpress view style is typically used to present a recursive data relationship. An example of this would be a DataSet with a DataRelation defined such that a row has a reference to another row, which has a reference to another row, etc., thus creating an n level hierarchy. A real world example of this would be a forum, where the first posting in a thread has an article ID, and the second and subsequent ones have an ID that relates to the article ID, and also to a parent post in the thread. This is what you see in OutlookExpress; you can take a look at the 'UltraTree NewsgroupReader' sample, which is included with the SDK, to see how all that is accomplished.
The reason I mention this is because if the data you are binding to is not recursively related, you might want to consider using the Grid ViewStyle instead.
Thanks Brian -
I had done something like this last night - I created an item class that contains a group name and a collection of items. In other words, the parent class had a collection of children, both parent and child were of the same type. This worked, and is ( somewhat ) along the same lines as what you have posted.
Thanks so much for the quick response.