Back to Devexpress

Expand and Collapse Nodes

wpf-9569-controls-and-libraries-data-grid-grid-view-data-layout-nodes-expand-and-collapse-nodes.md

latest5.4 KB
Original Source

Expand and Collapse Nodes

  • Jul 27, 2025
  • 3 minutes to read

The TreeListView allows users to expand/collapse parent nodes to show/hide their children:

Run Demo: TreeList ViewView Example: TreeListNode - Emulate Binding to the IsExpanded property

Expand and Collapse Nodes in UI

Users can expand/collapse nodes as follows:

  • Click a node’s expand button.
  • Focus a node and press Ctrl + Left / Right.

Note

Expand and Collapse Nodes in Code

Use the following API to expand/collapse nodes in code:

APIDescription
TreeListNodeBase.IsExpandedGets or sets whether the node is expanded.
TreeListView.ExpandNode / TreeListView.CollapseNodeExpands/collapses a node.
TreeListView.ChangeNodeExpandedGets or sets the expanded state of a node.
TreeListView.ExpandToLevelExpands the parent nodes down to the specified nesting level.
TreeListNodeBase.ExpandAll / TreeListNodeBase.CollapseAllExpands/collapses all child nodes within the node.
TreeListView.ExpandAllNodes / TreeListView.CollapseAllNodesExpands/collapses all nodes within the TreeListView.
TreeListView.AutoExpandAllNodesGets or sets whether all nodes are automatically expanded when the TreeListView is loading.

Before a node is expanded/collapsed, the TreeListView.NodeExpanding / TreeListView.NodeCollapsing event is raised.

After a node is expanded/collapsed, the TreeListView.NodeExpanded / TreeListView.NodeCollapsed event is raised.

View Example: Load Nodes Dynamically

Expand State

Use the following properties to bind node expand states to a property:

PropertyDescription
TreeListView.ExpandStateBindingGets or sets the binding that determines which nodes are expanded.
TreeListView.ExpandStateFieldNameGets or sets the name of the data source’s field that determines which nodes are expanded.

Note

The TreeListView.ExpandStateBinding property takes precedence over the TreeListView.ExpandStateFieldName property.

EnableDynamicLoading Property

The TreeListView in hierarchical binding mode creates child nodes dynamically when you expand their parent node.

Set the TreeListView.EnableDynamicLoading property to false to create all nodes at once when the tree is loading.

FetchSublevelChildrenOnExpand Property

The TreeListView in hierarchical binding mode fetches child nodes of sub-level nodes when you expand their parent node.

If the TreeListView.FetchSublevelChildrenOnExpand property is false , all the child nodes display expand buttons (even if they do not have children) after you expand their parent node. The expand button is hidden when you expand a sub-level node that does not contain child nodes.

The TreeListView.HasChildNodesPath property allows you to control expand buttons when sub-level children are not fetched.

ExpandNodesOnFiltering Property

Set the TreeListView.ExpandNodesOnFiltering property to true to expand a node if its child nodes contain the search text.

Tip

Topic : Filter Nodes