Expanding and Collapsing Nodes
- 2 minutes to read
Nodes with child nodes are called parent nodes. These nodes display expand buttons allowing end-users to show/hide their children. A node’s expanded state is specified by the TreeListNodeBase.IsExpanded property.
Expanding Nodes
To expand a node, do one of the following.
- Set the node’s TreeListNodeBase.IsExpanded property to true.
- Use the view’s TreeListView.ExpandNode method.
- Use the view’s TreeListView.ChangeNodeExpanded method with the isExpanded parameter set to true.
- Use the TreeListNodeBase.ExpandAll method to expand all child nodes.
- Use the TreeListView.ExpandAllNodes method to expand all nodes within a View.
Set the TreeListView.AutoExpandAllNodes property to true to expand all nodes automatically when the TreeListView is being loaded.
Before a node is expanded, the TreeListView.NodeExpanding event is raised. Handle this event to:
- Cancel the action by setting the event parameter’s TreeListNodeAllowEventArgs.Allow property to false;
- Dynamically create child nodes. In this instance, when expanding a node, you do not know whether it has child nodes or not. If the node has no child nodes, hide the expand button by setting the TreeListNode.IsExpandButtonVisible property to false.
After a node has been expanded, the View fires the TreeListView.NodeExpanded event.
Example: How to: Dynamically Load Nodes
Collapsing Nodes
To collapse a node, do one of the following.
- Set the node’s TreeListNodeBase.IsExpanded property to false.
- Use the view’s TreeListView.CollapseNode method.
- Use the view’s TreeListView.ChangeNodeExpanded method with the isExpanded parameter set to false.
- Use the TreeListNodeBase.CollapseAll method to collapse all child nodes.
- Use the TreeListView.CollapseAllNodes method to collapse all nodes within a View.
Before a node is collapsed, the TreeListView.NodeCollapsing event is raised. This allows you to cancel the action by setting the event parameter’s TreeListNodeAllowEventArgs.Allow property to false.
After a node has been collapsed, the View fires the TreeListView.NodeCollapsed event.
Expand State
Use the following properties to bind the expand state of check boxes to a property:
Property | Description |
---|---|
TreeListView.ExpandStateFieldName | Gets or sets the name of the data field within the items source that determines which nodes are expanded. |
TreeListView.ExpandStateBinding | Gets or sets the binding that determines which nodes are expanded. |
Note
The TreeListView.ExpandStateBinding property takes precedence over the TreeListView.ExpandStateFieldName property.