Skip to main content
A newer version of this page is available. .

Unbound Mode

  • 3 minutes to read

The Tree List control supports unbound mode, where you can manually create nodes. Unbound mode implies that the TreeList.DataSource property is set to null.

Online Video

WinForms Tree List - How to Create a Conventional TreeList.

Adding Columns and Nodes in Unbound Mode

Generally you should follow the steps below when customizing a Tree List control for use in unbound mode:

  1. Create columns.

    You can create columns at design time via the Tree List Designer, or in code via the TreeList.Columns collection.

    For columns, specify the type of data via the TreeListColumn.UnboundType property.

  2. Manually create nodes.

    Nodes can be manually created at design time via the Nodes Editor. At runtime, you can create nodes via the TreeList.AppendNode method.

To create a node in unbound mode, use the TreeList.AppendNode method. The method takes a nodeData parameter, and this specifies the data used to initialize the created node cells. This parameter value can be an array of values or a DataRow object. The number and order of items in the array/DataRow object must match the number and order of Tree List columns.

See How to: Create Nodes in Unbound Mode at Design Time and How to: Create Nodes in Unbound Mode in Code, for examples of populating a Tree List control in unbound mode.

Dynamic Loading

There are two data loading approaches in unbound mode. The first approach - create all the nodes at one time (for instance, on form loading). The second approach is to create root nodes on form loading and then provide child nodes dynamically, on demand, when parent nodes are expanded. Implementation of dynamic detail loading improves application performance, and reduces the data stored in memory for each parent node.

Basic steps of implementing dynamic loading are as follows:

  1. Create root nodes in a Tree List control.

    Root nodes can be created using the TreeList.AppendNode method, for instance on the application startup.

  2. For nodes that will have children, set the TreeListNode.HasChildren property to true.

    This results in displaying the expand button for every node of this kind. When an end-user clicks this button, the TreeList.BeforeExpand event fires.

  3. Handle the TreeList.BeforeExpand event to create child nodes for the node being expanded.

    For child nodes, you also need to set the TreeListNode.HasChildren property to true, if these nodes have their own children.

Export and Import Data

In unbound mode, you can export nodes and their data to a stream or file in XML format, and then load it later. To export the data, use the TreeList.ExportToXml. To import the previously saved data, use the TreeList.ImportFromXml method.

For more information on exporting data, see Export and Import Data.

Working in Unbound Mode

Every time the TreeList.AppendNode method or another method that modifies the node structure is called, the Tree List control performs an update. If you perform multiple subsequent calls to these methods, multiple updates take place. For performance reasons, you can avoid superfluous updates by enclosing your code with the TreeList.BeginUnboundLoad and TreeList.EndUnboundLoad methods. In this instance, the control will be updated only once, by the EndUnboundLoad method.

The following topic refers to members that may be useful to you when performing operations on the Tree List control in unbound mode: Member Table: Unbound Mode.


See Also