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

TreeList.KeyFieldName Property

Gets or sets the data source field that uniquely identifies records in the data source.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v18.2.dll

Declaration

[DefaultValue("ID")]
[XtraSerializableProperty]
public string KeyFieldName { get; set; }

Property Value

Type Default Description
String "ID"

The key identifier field name.

Remarks

The KeyFieldName and TreeList.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 KeyFieldName and TreeList.ParentFieldName fields. You need to activate the TreeListOptionsBehavior.PopulateServiceColumns option to create these columns.

Note

The data source field specified by the KeyFieldName property must store unique values.

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();
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the KeyFieldName 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.

See Also