Skip to main content
All docs
V22.1

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.v22.1.dll

Declaration

public IChildNodesSelector ChildNodesSelector { get; set; }

Property Value

Type Description
DevExpress.Xpf.Grid.IChildNodesSelector

The child nodes selector.

Remarks

The Child Nodes Selector returns node children. You can use this approach 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 DevExpress.Xpf.Grid.IChildNodeSelector, and override the SelectChildren 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>
    
See Also