Skip to main content
All docs
V24.1

TreeViewControl.HasChildNodesPath Property

Gets or sets the name of a data source’s field that determines whether a node has children. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

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

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public string HasChildNodesPath { get; set; }

Property Value

Type Description
String

The name of a data source’s field that determines whether a node has children.

Remarks

The HasChildNodesPath property works only when you specify the ChildNodesPath property.

To build a tree structure, set the ChildNodesPath property to a field that contains child nodes (the Employees field in the code sample below).

<dxg:TreeViewControl ItemsSource="{Binding EmployeeDepartments}" 
                     ChildNodesPath="Employees" 
                     TreeViewFieldName="Name"
                     HasChildNodesPath="HasChildNodes"/>
using System.Windows;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using DevExpress.Mvvm;

namespace TreeViewChildNodesSelector {
    public class MainWindowViewModel : ViewModelBase {
        public MainWindowViewModel() {
            EmployeeDepartments = Departments.GetDepartments();
        }
        public List<EmployeeDepartment> EmployeeDepartments { get; set; }
    }
    public class Employee {
        public Employee(int id, string name) {
            ID = id;
            Name = name;
        }
        public int ID { get; set; }
        public string Name { get; set; }
    }
    public class EmployeeDepartment {
        public string Name { get; set; }
        public ObservableCollection<Employee> Employees { get; }
        public bool HasChildNodes { get; set; }

        public EmployeeDepartment(string name, IEnumerable<Employee> employees) {
            Name = name;
            Employees = new ObservableCollection<Employee>(employees);
        }
    }
    public static class Departments {
        public static List<EmployeeDepartment> GetDepartments() {
            List<EmployeeDepartment> departments = new List<EmployeeDepartment> {
                new EmployeeDepartment("Management", new Employee[] {
                new Employee(0, "Gregory S. Price")
                }, true),
                new EmployeeDepartment("Marketing", new Employee[] {
                new Employee(1, "Irma R. Marshall"),
                new Employee(2, "Brian C. Cowling"),
                new Employee(3, "Thomas C. Dawson"),
                new Employee(4, "Bryan R. Henderson"),
                }, true),
                new EmployeeDepartment("Operations", new Employee[] {
                new Employee(5, "John C. Powell"),
                new Employee(6, "Harold S. Brandes"),
                new Employee(7, "Jan K. Sisk"),
                new Employee(8, "Sidney L. Holder"),
                }, true),
                new EmployeeDepartment("Production", new Employee[] {
                new Employee(9, "Christian P. Laclair"),
                new Employee(10, "James L. Kelsey"),
                new Employee(11, "Howard M. Carpenter"),
                new Employee(12, "Jennifer T. Tapia"),
                },false),
                new EmployeeDepartment("Finance", new Employee[] {
                new Employee(13, "Karen J. Kelly"),
                new Employee(14, "Judith P. Underhill"),
                new Employee(15, "Russell E. Belton"),
                },false)
            };
            return departments;
        }
    }
}
See Also