[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Implementation Details
   [Expand]Views
   [Expand]Grid View Data Layout
   [Collapse]Binding to Data
     Binding to Data Overview
     Binding to ICollectionView
     Virtual Source, Server Mode, Instant Feedback Components
    [Expand]Server Mode
    [Expand]Binding to any Data Source with Virtual Sources
    [Collapse]TreeListView Data Binding
      Bind to Hierarchical Data Overview
      Bind to Self-Referential Data Structure
      Bind to Hierarchical Data Structure
      Unbound Mode
     Applying Data Annotations
     Unbound Columns
     Managing Multi-Thread Data Updates
   [Expand]Master-Detail Data Representation
   [Expand]Data Editing and Validation
   [Expand]Grouping
   [Expand]Filtering and Searching
   [Expand]Sorting
   [Expand]Data Summaries
   [Expand]Paging and Scrolling
   [Expand]Focus, Navigation, Selection
   [Expand]Drag-and-Drop
   [Expand]Conditional Formatting
   [Expand]Appearance Customization
   [Expand]MVVM Enhancements
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Miscellaneous
   [Expand]Performance Improvement
   [Expand]Design-Time Features
   [Expand]Visual Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Bind to Hierarchical Data Structure

A hierarchical data structure is a set of nested objects where a children field contains child records. Parents and children can be of different object types.

The DataControlBase.ItemsSource property contains only data items that correspond to root nodes. Use the following approaches to make the TreeListView work with the hierarchical data structure:

  • Child Nodes Path - Set a path to the children field. Use this approach only when child and parent fields have the same object type.
  • Child Nodes Selector - Create a selector that returns node children. You can use this approach for different object types.
  • Hierarchical Data Templates - Create a template for different data types.

Expanded Child Nodes Path

Use the Child Nodes Path to bind the TreeListView to a collection if all objects have the same children field. An example of such a structure is shown below:

  1. Set the TreeListView.ChildNodesPath property to the children field name.
  2. Set the TreeListView.TreeDerivationMode property to ChildNodesSelector.

    In the code sample below, the Tasks field is the children field:

Expanded Child Nodes Selector

Tip

Demo: Child Nodes Selector

Requires installation of WPF Subscription. Download

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

  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:

  2. Assign the Child Nodes Selector to the TreeListView.ChildNodesSelector property.

  3. Set the TreeListView.TreeDerivationMode property to ChildNodesSelector.

Tip

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

Expanded Hierarchical Data Templates

Tip

Demo: Hierarchical Data Templates

Requires installation of WPF Subscription. Download

You can use templates to create a hierarchical data structure in the TreeListView. An example of this structure is shown below:

If all objects have the same children field, create a hierarchical data template and assign it to the TreeListView.DataRowTemplate property. You can put hierarchical data templates into resources. Specify the data type to which a template should be applied:

If all objects have different children fields:

  1. Create a template selector that implements the System.Windows.Controls.DataTemplateSelector and overrides the SelectTemplate method.

  2. Assign the template selector to the TreeListView.DataRowTemplateSelector property.

  3. Set the TreeListView.TreeDerivationMode property to HierarchicalDataTemplate.

Note

Expanded Related API

Sort and Filter in Hierarchical Binding Mode

When the TreeListView is in hierarchical binding mode, users can sort and filter values if object types are the same. Set the TreeListView.AutoDetectColumnTypeInHierarchicalMode property to true to allow sorting/filtering (enabled by default).

Control whether to Create Child Nodes

You can control whether to create child nodes for a node. The following example shows how to prevent the TreeListView from creating child nodes for the Information Gathering node:

  1. In a data source, create a field that determines whether a node has children (the HasChildNodes field in the code sample below):

  2. Specify the TreeListView.HasChildNodesPath property to this field's name.

Is this topic helpful?​​​​​​​