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

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 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.

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.