Hoa add root node to selfreferenced database binded RadTree

2 posts, 1 answers
  1. Anoop
    Anoop avatar
    18 posts
    Member since:
    Dec 2012

    Posted 29 Dec 2012 Link to this post

    I want to add root node to self referenced database binded RadTree View.
    RadContextMenu contextMenu = new RadContextMenu();
    RadMenuItem addRootNodeItem = new RadMenuItem("New Node");
    addRootNodeItem.Click += addRootNodeItem_Click;
    radTreeView1.RadContextMenu = contextMenu;

    void addRootNodeItem_Click(object sender, EventArgs e)
    RadTreeNode RootNode = new RadTreeNode("New Node");

    I tried above code but which returns error Object reference not set to an instant of of an object.
    Any other method to do this?
  2. Answer
    Ivan Todorov
    Ivan Todorov avatar
    688 posts

    Posted 03 Jan 2013 Link to this post

    Hi Anoop,

    Thank you for contacting us.

    You are receiving this exception because you are adding an unbound node which does not have an associated row from the underlying data source. To add new nodes to a data bound RadTreeView, you should add records directly to the data source:
    private void radButtonAdd_Click(object sender, EventArgs e)
        TreeViewTestDataSet.NodeRow row = this.treeViewTestDataSet.Node.NewNodeRow();
        row.Name = "New Node";

    I hope this will help. Should you have any additional questions, feel free to ask.

    Kind regards,
    Ivan Todorov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. DevCraft banner
Back to Top