Add Values to a Row of TreeList of DevExpress

JM Olesco picture JM Olesco · Mar 19, 2013 · Viewed 10.7k times · Source

I am creating an application and used a TreeList of DevExpress. Currently, I am the one who created the nodes of TreeList in the node editor and planned that all data will be read or transferred in my TreeList by adding it to the specified column.

How could I achieve this?

Here is my code

tbl.Rows.Add(4,  4, 10 );
tbl.Rows.Add(5, 5, 30);

but it doesn't work at all. I'm just getting an exception.

Answer

J.Hudler picture J.Hudler · Mar 19, 2013

Devexpress controls work differently than the built-in winforms controls.

Here's an example on how you could add items to your TreeView in an unbound manner:

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

public class Form1
{

    private void Form1_Load(System.Object sender, System.EventArgs e)
    {
        TreeList1.Columns.Clear();
        TreeListColumn newColumn = TreeList1.Columns.Add();
        newColumn.Caption = "Tree Column";
        newColumn.Visible = true;

        TreeList1.Nodes.Clear();
        TreeListNode rootNode = TreeList1.Nodes.Add({ "Root Node" });
        TreeListNode child1 = rootNode.Nodes.Add({ "Child 1" });
        child1.Nodes.Add({ "GrandChild 1.1" });
        child1.Nodes.Add({ "GrandChild 1.2" });

        TreeListNode child2 = rootNode.Nodes.Add({ "Child 2" });
        child2.Nodes.Add({ "GrandChild2.1" });
        child2.Nodes.Add({ "GrandChild2.2" });
        child2.Nodes.Add({ "GrandChild2.3" });

        TreeList1.RefreshNode(rootNode);
    }
}

If you need more code samples, click below - you'll find plenty of them there:

http://documentation.devexpress.com/#WindowsForms/CustomDocument5558