TreeList.ParentFieldName Property
Gets or sets the data source field that identifies each record’s parent.
Namespace: DevExpress.XtraTreeList
Assembly: DevExpress.XtraTreeList.v18.2.dll
Declaration
[DefaultValue("ParentID")]
[XtraSerializableProperty]
public string ParentFieldName { get; set; }
Property Value
Type | Default | Description |
---|---|---|
String | "ParentID" | The parent identifier field name. |
Remarks
The TreeList.KeyFieldName and ParentFieldName properties specify Key and Parent fields in the bound data source that are used to set up a tree-like structure in a Tree List control. See Tree Generation Algorithm in the Tree List to learn more.
The Tree List control does not automatically create columns specified in the TreeList.KeyFieldName and ParentFieldName fields. You need to activate the TreeListOptionsBehavior.PopulateServiceColumns option to create these columns.
A record is recognized as a root record if its ParentFieldName field satisfies any of the following conditions:
- equals TreeList.RootValue (the default is 0)
- equals null or DBNull.Value
- doesn’t match any of the nodes’ key field values, and is not equal to the RootValue
The code sample below illustrates how to add a child record to a tree list when users right-click on a node.
System.Data.DataSet xmlDataSet = new System.Data.DataSet("XML DataSet");
xmlDataSet.ReadXml(@"D:\Tmp\employees.xml");
treeList1.DataSource = xmlDataSet.Tables["employee"];
treeList1.KeyFieldName = "id";
treeList1.ParentFieldName = "reportsTo";
treeList1.RowClick += TreeList1_RowClick;
private void TreeList1_RowClick(object sender, DevExpress.XtraTreeList.RowClickEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
DataRow row = xmlDataSet.Tables["employee"].NewRow();
row["id"] = xmlDataSet.Tables["employee"].Rows.Count + 1;
row["reportsTo"] = e.HitInfo.Node.GetValue("id");
xmlDataSet.Tables["employee"].Rows.Add(row);
e.HitInfo.Node.Expand();
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the ParentFieldName property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.