Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TreeViewControl.ChildNodesSelector Property

Gets or sets a selector that returns the list of child nodes for the processed node. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.2.dll

NuGet Package: DevExpress.Wpf.Grid.Core

#Declaration

public IChildNodesSelector ChildNodesSelector { get; set; }

#Property Value

Type Description
IChildNodesSelector

The child nodes selector.

#Remarks

The Child Nodes Selector returns node children. You can use the returned list of child nodes to create a hierarchical data structure for different object types.

public class ProjectObject : BaseObject {
    public ObservableCollection<ProjectStage> Stages { get; set; }
}

public class ProjectStage : BaseObject {
    public ObservableCollection<Task> Tasks { get; set; }
}

public class Task : BaseObject {
    State state;
    // ...
}
  1. Create a selector class that implements IChildNodesSelector, and override the SelectChildren(Object) method that returns node children.

    For the Project-Stage-Task class structure, the selector class is as follows:

    public class CustomChildrenSelector : IChildNodesSelector {
        public IEnumerable SelectChildren(object item) {
            if (item is Task)
                return null;
            else if (item is ProjectStage)
                return (item as ProjectStage).Tasks;
            else if (item is ProjectObject)
                return (item as ProjectObject).Stages;
            return null;
        }
    }
    
  2. Assign the Child Nodes Selector to the ChildNodesSelector property.

    <dxg:TreeViewControl ItemsSource="{Binding DataItems}" 
                         TreeViewFieldName="Name">
        <dxg:TreeViewControl.ChildNodesSelector>
            <local:CustomChildrenSelector/>
        </dxg:TreeViewControl.ChildNodesSelector>
    </dxg:TreeViewControl>
    

Refer to the following help topic for more information: Hierarchical Data Structure.

See Also