Skip to main content
All docs
V25.1
  • TreeViewControl.Nodes Property

    Gets the collection of root nodes.

    Namespace: DevExpress.Xpf.Grid

    Assembly: DevExpress.Xpf.Grid.v25.1.dll

    NuGet Package: DevExpress.Wpf.Grid.Core

    Declaration

    public TreeListNodeCollection Nodes { get; }

    Property Value

    Type Description
    TreeListNodeCollection

    The collection of root nodes.

    Remarks

    You can use the Nodes property to create an unbound tree without a data source:

    Tree View Control - Unbound Nodes

    <dxg:TreeViewControl AutoExpandAllNodes="True">
        <dxg:TreeViewControl.Nodes>
            <dxg:TreeListNode Content="Root Node 1">
                <dxg:TreeListNode.Nodes>
                    <dxg:TreeListNode Content="Level 1">
                        <dxg:TreeListNode.Nodes>
                            <dxg:TreeListNode Content="Level 2"/>
                        </dxg:TreeListNode.Nodes>
                    </dxg:TreeListNode>
                </dxg:TreeListNode.Nodes>
            </dxg:TreeListNode>
            <dxg:TreeListNode Content="Root Node 2">
                <dxg:TreeListNode.Nodes>
                    <dxg:TreeListNode Content="Level 1"/>
                </dxg:TreeListNode.Nodes>
            </dxg:TreeListNode>
        </dxg:TreeViewControl.Nodes>
    </dxg:TreeViewControl>
    

    Specify the TreeViewFieldName property to display data in the TreeViewControl if you set an object as a node’s content.

    Iterate Through Nodes

    Create a new instance of the TreeListNodeIterator class to iterate through nodes. You can specify a start node or the collection of nodes, and whether to process only visible nodes.

    Note

    If you specified the collection of nodes, the Node Iterator starts to process nodes from the first node in the specified collection.

    The following code sample iterates through all visible nodes to expand nodes that have more than three child nodes.

    Tree View Control - Node Iterator

    <dxg:TreeViewControl x:Name="treeview"
                         Loaded="treeview_Loaded"
                         ... />
    
    void SmartExpandNodes(int minChildCount) {
        foreach (DevExpress.Xpf.Grid.TreeListNode node in new DevExpress.Xpf.Grid.TreeListNodeIterator(treeview.Nodes, true)) {
            node.IsExpanded = node.Nodes.Count >= minChildCount;
        }
    }
    void treeview_Loaded(object sender, RoutedEventArgs e) {
        SmartExpandNodes(3);
    }
    
    See Also