Completed
Last Updated: 10 Jun 2016 07:27 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 09 May 2016 13:29
Category: TreeView
Type: Bug Report
0
FIX. RadTreeView - Nodes.Clear() throws NullReferenceException in self-reference tree
To reproduce: select a node and click the button. Note: it may be necessary to perform this several times.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private List<DataObject> GetDataList()
    {
        var ret = new List<DataObject>();

        ret.Add(new DataObject() { Node = "A", Parent = null });
        ret.Add(new DataObject() { Node = "B", Parent = "A" });
        ret.Add(new DataObject() { Node = "C", Parent = "B" });
        ret.Add(new DataObject() { Node = "D", Parent = "B" });

        return ret;
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        radTreeView1.Nodes.Clear(); 
        radTreeView1.DisplayMember = "Node";
        radTreeView1.ChildMember = "Node";
        radTreeView1.ParentMember = "Parent";
        radTreeView1.DataSource = GetDataList();
        radTreeView1.ExpandAll();
    }
}

public class DataObject
{
    public string Node { get; set; }

    public string Parent { get; set; }
}

Workaround: instead of clearing the nodes, set the DataSource property to null.
0 comments