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.1.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
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;
// ...
}
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; } }
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.