wpf-9569-controls-and-libraries-data-grid-grid-view-data-layout-nodes-expand-and-collapse-nodes.md
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
Users can expand/collapse nodes as follows:
Note
Use the following API to expand/collapse nodes in code:
| API | Description |
|---|---|
| TreeListNodeBase.IsExpanded | Gets or sets whether the node is expanded. |
| TreeListView.ExpandNode / TreeListView.CollapseNode | Expands/collapses a node. |
| TreeListView.ChangeNodeExpanded | Gets or sets the expanded state of a node. |
| TreeListView.ExpandToLevel | Expands the parent nodes down to the specified nesting level. |
| TreeListNodeBase.ExpandAll / TreeListNodeBase.CollapseAll | Expands/collapses all child nodes within the node. |
| TreeListView.ExpandAllNodes / TreeListView.CollapseAllNodes | Expands/collapses all nodes within the TreeListView. |
| TreeListView.AutoExpandAllNodes | Gets 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
Use the following properties to bind node expand states to a property:
| Property | Description |
|---|---|
| TreeListView.ExpandStateBinding | Gets or sets the binding that determines which nodes are expanded. |
| TreeListView.ExpandStateFieldName | Gets 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.
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.
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.
Set the TreeListView.ExpandNodesOnFiltering property to true to expand a node if its child nodes contain the search text.
Tip
Topic : Filter Nodes