wpf-devexpress-dot-xpf-dot-grid-dot-treeviewcontrol-4f524f10.md
Gets or sets the value that root nodes contain in the field specified by the ParentFieldName property.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public object RootValue { get; set; }
Public Property RootValue As Object
| Type | Description |
|---|---|
| Object |
The root value.
|
Set the TreeDerivationMode property to Selfreference to enable the self-referential mode.
To build a tree structure, your data source should contain the following two fields with the same data type:
If a node’s parent field value does not point to any other node, the TreeViewControl adds this node to the collection of root nodes (TreeViewControl.Nodes).
<dxg:TreeViewControl ItemsSource="{Binding Employees}"
KeyFieldName="ID"
ParentFieldName="ParentID"
TreeViewFieldName="Name"
TreeDerivationMode="Selfreference"/>
You can specify the RootValue property’s value, to add to the collection of root nodes only those nodes whose parent field value matches RootValue. If the node’s parent field value does not match RootValue and does not point to any other node, this node is not displayed in the TreeViewControl.
<dxg:TreeViewControl ItemsSource="{Binding Employees}"
KeyFieldName="ID"
ParentFieldName="ParentID"
TreeViewFieldName="Name"
TreeDerivationMode="Selfreference">
<dxg:TreeViewControl.RootValue>
<sys:Int32>1</sys:Int32>
</dxg:TreeViewControl.RootValue>
</dxg:TreeViewControl>
public class Employee : BindableBase {
public int ID { get; set; }
public int ParentID { get; set; }
public string Name { get; set; }
public string Position { get; set; }
public string Department { get; set; }
}
public static class Staff {
public static List<Employee> GetStaff() {
List<Employee> staff = new List<Employee> {
new Employee() { ID = 1, ParentID = 0, Name = "Gregory S. Price", Department = "", Position = "President" },
new Employee() { ID = 2, ParentID = 1, Name = "Irma R. Marshall", Department = "Marketing", Position = "Vice President" },
new Employee() { ID = 3, ParentID = 1, Name = "John C. Powell", Department = "Operations", Position = "Vice President" },
new Employee() { ID = 4, ParentID = 1, Name = "Christian P. Laclair", Department = "Production", Position = "Vice President" },
new Employee() { ID = 5, ParentID = 1, Name = "Karen J. Kelly", Department = "Finance", Position = "Vice President" },
new Employee() { ID = 6, ParentID = 2, Name = "Brian C. Cowling", Department = "Marketing", Position = "Manager" },
new Employee() { ID = 7, ParentID = 2, Name = "Thomas C. Dawson", Department = "Marketing", Position = "Manager" },
new Employee() { ID = 8, ParentID = 2, Name = "Angel M. Wilson", Department = "Marketing", Position = "Manager" },
new Employee() { ID = 9, ParentID = 2, Name = "Bryan R. Henderson", Department = "Marketing", Position = "Manager" },
new Employee() { ID = 10, ParentID = 3, Name = "Harold S. Brandes", Department = "Operations", Position = "Manager" },
new Employee() { ID = 11, ParentID = 3, Name = "Michael S. Blevins", Department = "Operations", Position = "Manager" },
new Employee() { ID = 12, ParentID = 3, Name = "Jan K. Sisk", Department = "Operations", Position = "Manager" },
new Employee() { ID = 13, ParentID = 3, Name = "Sidney L. Holder", Department = "Operations", Position = "Manager" },
new Employee() { ID = 14, ParentID = 4, Name = "James L. Kelsey", Department = "Production", Position = "Manager" },
new Employee() { ID = 15, ParentID = 4, Name = "Howard M. Carpenter", Department = "Production", Position = "Manager" },
new Employee() { ID = 16, ParentID = 4, Name = "Jennifer T. Tapia", Department = "Production", Position = "Manager" },
new Employee() { ID = 17, ParentID = 5, Name = "Judith P. Underhill", Department = "Finance", Position = "Manager" },
new Employee() { ID = 18, ParentID = 5, Name = "Russell E. Belton", Department = "Finance", Position = "Manager" }
};
return staff;
}
}
public class MainWindowViewModel : ViewModelBase {
public MainWindowViewModel() {
Employees = Staff.GetStaff();
}
public List<Employee> Employees { get; private set; }
}
Public Class Employee
Inherits BindableBase
Public Property ID As Integer
Public Property ParentID As Integer
Public Property Name As String
Public Property Position As String
Public Property Department As String
End Class
Module Staff
Function GetStaff() As List(Of Employee)
Dim staff As List(Of Employee) = New List(Of Employee) From {
New Employee() With { .ID = 1, .ParentID = 0, .Name = "Gregory S. Price", .Department = "", .Position = "President" },
New Employee() With { .ID = 2, .ParentID = 1, .Name = "Irma R. Marshall", .Department = "Marketing", .Position = "Vice President" },
New Employee() With { .ID = 3, .ParentID = 1, .Name = "John C. Powell", .Department = "Operations", .Position = "Vice President" },
New Employee() With { .ID = 4, .ParentID = 1, .Name = "Christian P. Laclair", .Department = "Production", .Position = "Vice President" },
New Employee() With { .ID = 5, .ParentID = 1, .Name = "Karen J. Kelly", .Department = "Finance", .Position = "Vice President" },
New Employee() With { .ID = 6, .ParentID = 2, .Name = "Brian C. Cowling", .Department = "Marketing", .Position = "Manager" },
New Employee() With { .ID = 7, .ParentID = 2, .Name = "Thomas C. Dawson", .Department = "Marketing", .Position = "Manager" },
New Employee() With { .ID = 8, .ParentID = 2, .Name = "Angel M. Wilson", .Department = "Marketing", .Position = "Manager" },
New Employee() With { .ID = 9, .ParentID = 2, .Name = "Bryan R. Henderson", .Department = "Marketing", .Position = "Manager" },
New Employee() With { .ID = 10, .ParentID = 3, .Name = "Harold S. Brandes", .Department = "Operations", .Position = "Manager" },
New Employee() With { .ID = 11, .ParentID = 3, .Name = "Michael S. Blevins", .Department = "Operations", .Position = "Manager" },
New Employee() With { .ID = 12, .ParentID = 3, .Name = "Jan K. Sisk", .Department = "Operations", .Position = "Manager" },
New Employee() With { .ID = 13, .ParentID = 3, .Name = "Sidney L. Holder", .Department = "Operations", .Position = "Manager" },
New Employee() With { .ID = 14, .ParentID = 4, .Name = "James L. Kelsey", .Department = "Production", .Position = "Manager" },
New Employee() With { .ID = 15, .ParentID = 4, .Name = "Howard M. Carpenter", .Department = "Production", .Position = "Manager" },
New Employee() With { .ID = 16, .ParentID = 4, .Name = "Jennifer T. Tapia", .Department = "Production", .Position = "Manager" },
New Employee() With { .ID = 17, .ParentID = 5, .Name = "Judith P. Underhill", .Department = "Finance", .Position = "Manager" },
New Employee() With { .ID = 18, .ParentID = 5, .Name = "Russell E. Belton", .Department = "Finance", .Position = "Manager" }
}
Return staff
End Function
End Module
Public Class MainWindowViewModel
Inherits ViewModelBase
Public Sub New()
Employees = Staff.GetStaff()
End Sub
Public Property Employees As List(Of Employee)
End Class
See Also