[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Collapse]Tree List
   [Expand]Product Information
   [Collapse]Feature Center
    [Collapse]Data Binding
      Bound Mode
      Tree Generation Algorithm in the Tree List
      Virtual Mode (Dynamic Data Loading) Using Events (Tree List Level)
      Virtual Mode - Binding to a Hierarchical Business Object (Data Source Level)
      Unbound Mode
      Unbound Columns
      Posting Data to a Connected Database in ADO.NET
    [Expand]Data Editing
    [Expand]Data Presentation
    [Expand]Appearances and Look And Feel
    [Expand]Focus, Selection and Navigation
     Formatting Cell Values
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End User Capabilities
   [Expand]Member Tables
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Tree Generation Algorithm in the Tree List

The Tree List control displays hierarchical data structures in which nodes can have other nodes as children. This topic shows how to define the parent-child relationship at data source level for Tree List controls in Bound Mode.

Expanded Parent-Child Relationships

The data source bound to the Tree List control requires two additional fields:

  • Key Field - This field contains unique values that identify records in the data source. Assign this field name to the TreeList.KeyFieldName property.
  • Parent Field - This field refers to a corresponding parent node's Key Field. Assign this field name to the TreeList.ParentFieldName property

The image below is an example of a data source with an ID column that contains Key Fields. The PARENTID column values are Parent Fields, which identify parent rows.

The following image shows the same data source bound to the Tree List control. The TreeList.KeyFieldName property is set to "ID" and the TreeList.ParentFieldName property to "PARENTID".

Expanded Root Nodes

Root nodes are parentless (for example, the "Corporate Headquarters" node in the image above). All root nodes must have their Parent Field values (TreeList.ParentFieldName) set to TreeList.RootValue (by default, 0).

A parentless node whose Parent Field value does not match TreeList.RootValue is also recognized as a root node. If the Tree List control contains these parentless nodes, the control re-builds the hierarchy tree in many cases (for instance, when data is updated or sorted). You may notice flickering and unexpected scroll behavior. To avoid these issues, we suggest that you always sync Parent Field values with TreeList.RootValue for root nodes.

Related API

Expanded Example

The following example creates a TreeList (see TreeList) at runtime and shows how to perform basic customization tasks:

  • Bind the treelist to a data source
  • Specify the key fields that form a hierarchy
  • Access automatically created columns
  • Set a custom row height
  • Customize column captions (using HTML tags) and cell appearance settings
  • Create unbound columns and create Excel-style format conditions based on these column values
  • Assign an in-place editor (a spin editor) to columns
  • Sort data
  • Calculate total summaries
  • Filter nodes
  • Hide columns and calculate column "best" widths
  • Locate and expand nodes
  • Focus a specific cell
  • Specify DataAnnotation attributes at the data source level (the "p0" display format for the MarketShare field)

Expanded See Also

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