How do I data bind a tree to a collection of .NET objects?

Problem Statement

Users navigate through application features or information categorized from broad categories to more specific tasks or reports.  For instance, financial representatives may be responsible for a wealth management portfolio having separate categories for high net worth clients, qualified investor clients, and foreign investor clients.  Within each category the representative sees the names of their assigned clients and can select a name to see more information.

Your application already treats these categories as .NET collections, and individual records are reflected using a .NET business objects with some identifiable property (such as the client's name).

When categories and/or subcategories may contain variable contents from a data source, a tree is preferred over a menu.

Infragistics Solutions

ASP.NET     Windows Forms    
 

Add the WebTree control to your Web form and add code in the code-behind to iterate over the contents of your top-level .NET collection object.  For each item you want to appear as a leaf (without children, i.e., an individual client) in the WebTree use the Add method on the Nodes collection.  This will create a new Node and you can specify properties like its Text property (i.e., the client's full name.)  For each item that you want to appear as a category or container, create a new Node object, use the Add method to add it to a parent Nodes collection,  and set its Text property to the category’s name (i.e., "High Net Worth clients.")  Then iterate over the .NET objects in this sub-collection, adding them as children to this Node.

You have complete control over mapping which properties on your .NET business objects are displayed as the text labels of individual tree nodes using this approach.  A variety of images can be associated with tree nodes based on your business objects' state, including different images based on whether the tree node is selected or moused over.  WebTree also supports associating a hyperlink with each node in the TargetUrl property that can be triggered on selection, and which can load new Web content into another frame by id using the TargetFrame property.

Other Solutions in the Data Binding Category

More Scenario Solutions...