Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Create Nodes in Unbound Mode in Code

  • 2 minutes to read

The following code shows how to manually populate a TreeList control with nodes in unbound mode.

To add nodes in unbound mode, utilize the TreeList.AppendNode method. Data that is passed to this method must match the TreeList columns. So, the TreeList columns are created before the nodes are created.

Note that calls to the methods used to create nodes are wrapped with the TreeList.BeginUnboundLoad and TreeList.EndUnboundLoad methods. This reduces the control’s updates to a minimum, and thus improves performance.

The following image displays the result.

TreeList.AppeandMode_ex

using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Nodes;

private void Form1_Load(object sender, EventArgs e) {
    CreateColumns(treeList1);
    CreateNodes(treeList1);
}

private void CreateColumns(TreeList tl) {
    // Create three columns
    tl.BeginUpdate();
    TreeListColumn col1 = tl.Columns.Add();
    col1.FieldName = "Customer";
    col1.Caption = "Customer";
    col1.VisibleIndex = 0;
    TreeListColumn col2 = tl.Columns.Add();
    col2.FieldName = "Location";
    col2.Caption = "Location";
    col2.VisibleIndex = 1;
    TreeListColumn col3 = tl.Columns.Add();
    col3.FieldName = "Phone";
    col3.Caption = "Phone";
    col3.VisibleIndex = 2;
    tl.EndUpdate();
}

private void CreateNodes(TreeList tl) {
    tl.BeginUnboundLoad();
    // Create a root node
    TreeListNode parentForRootNodes = null;
    TreeListNode rootNode = tl.AppendNode(
        new object[] { "Alfreds Futterkiste", "Germany, Obere Str. 57", "030-0074321" },
        parentForRootNodes);
    // Create a child of the rootNode
    tl.AppendNode(new object[] { "Suyama, Michael", "Obere Str. 55", "030-0074263" }, rootNode);
    // Create more nodes
    // ...
    tl.EndUnboundLoad();
}