Skip to main content
A newer version of this page is available. .

Tree Generation Algorithm in the Tree List

  • 2 minutes to read

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 the data source level for the Tree List control that functions in bound mode.

Parent-Child Relationships

The data source you bind to the Tree List control must have two additional fields:

  • Key Field - This field uniquely identifies each record in the data source. Assign this field name to the TreeList.KeyFieldName property.
  • Parent Field - This field refers to the Key Field of a corresponding parent node. Assign this field name to the TreeList.ParentFieldName property

Consider the following example of such a data source. The ID column contains Key Fields. The PARENTID column values are Parent Fields, which identify parent rows.

TreeGeneration_DataSource

Binding this data source to the Tree List control, setting the TreeList.KeyFieldName property to “ID”, and the TreeList.ParentFieldName property to “PARENTID”, results in the following:

TreeGeneration_res1

Root Nodes

Root nodes do not have parent nodes (see the “Corporate Headquarters” node in the image above). To identify root nodes in the data source, set their Parent Field values to 0, null or DBNull.Value. Instead of 0, you can use a custom Parent Field value to identify root nodes by assigning this value to the TreeList.RootValue property.

A record is also recognized as a root record if its TreeList.ParentFieldName field doesn’t match any of the nodes’ key field values, and is not equal to the RootValue.

 

Note

Related API * TreeList.KeyFieldName - Gets or sets a value specifying the key field of the data source bound to the Tree List control.