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 data source level for Tree List controls in bound mode.

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.

TreeGeneration_DataSource

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”.

TreeGeneration_res1

Root Nodes

Root nodes do not have parent nodes (for example, 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. You can also 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 does not match any of the nodes’ key field values and is not equal to the RootValue.

 

Note

Related API * TreeList.KeyFieldName - Gets or sets the data source field that uniquely identifies records in the data source.

See Also