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 TreeListNode.IsExpanded property.
#Expanding Nodes
To expand a node, do one of the following.
- Set the node's TreeListNode.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 TreeListNode.ExpandAll method to expand all child nodes.
- Use the TreeListView.ExpandAllNodes method to expand all nodes within a View.
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.
#Collapsing Nodes
To collapse a node, do one of the following.
- Set the node's TreeListNode.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 TreeListNode.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.