Skip to main content

TreeListView.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.v23.2.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public IChildNodesSelector ChildNodesSelector { get; set; }

Property Value

Type Description
IChildNodesSelector

The child nodes selector.

Remarks

Run Demo: Child Nodes Selector View Example: Use the Child Nodes Selector to Display Hierarchical Data

Use the Child Nodes Selector to create a hierarchical data structure in the TreeListView. An example of this structure is shown below:

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 ProjectStage)
                return ((ProjectStage)item).Tasks;
            else if (item is ProjectObject)
                return ((ProjectObject)item).Stages;
            return null;
        }
    }
    
  2. Assign the Child Nodes Selector to the ChildNodesSelector property.

  3. Set the TreeListView.TreeDerivationMode property to ChildNodesSelector.

    <dxg:TreeListControl ...>
        <dxg:TreeListControl.Resources>
            <local:CustomChildrenSelector x:Key="childrenSelector"/>
        </dxg:TreeListControl.Resources>
        <dxg:TreeListControl.View>
            <dxg:TreeListView TreeDerivationMode="ChildNodesSelector"
                              ChildNodesSelector="{StaticResource childrenSelector}"/>
        </dxg:TreeListControl.View>
    </dxg:TreeListControl>
    

Tip

If all objects have the same children field, assign its name to the TreeListView.ChildNodesPath property. Otherwise, create a Child Nodes Selector.

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the ChildNodesSelector property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also