Declined
Last Updated: 09 Oct 2014 10:49 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 09 Sep 2014 14:19
Category: TreeView
Type: Bug Report
0
FIX. RadTreeView - NullReferenceException when rebinding
To reproduces: add a RadTreeView and set up Object-relational hierarchy. Use the following code:

NorthwindEntities context = new NorthwindEntities();

public Form1()
{
    InitializeComponent();

    context.Categories.Load();
    context.Products.Load();

    this.radTreeView1.DataSource = context.Categories.Local.ToBindingList();
    this.radTreeView1.DisplayMember = "CategoryName\\ProductName";
    this.radTreeView1.ChildMember = "Categories\\Products";
}

private void radButton1_Click(object sender, EventArgs e)
{
    this.radTreeView1.ChildMember = "Products\\Categories";
    this.radTreeView1.DisplayMember = "ProductName\\CategoryName"; 
    this.radTreeView1.DataSource = context.Products.Local.ToBindingList();
}

When you click the RadButton, NullReferenceException occurs.

Resolution: Add more descriptive exception message. 
1 comment
ADMIN
Ivan Todorov
Posted on: 02 Oct 2014 08:24
This behavior is expected. When you are changing the ChildMember, the tree view tries to update but the DataSource is still set with the old collection, hence the properties from the ChildMember not being found and the exception being thrown. And vice versa, if you first change the DataSource property, the ChildMemeber is still set with the properties relevant to the old data source. To avoid this, you need to set the DataSource to null first. With the next versions, a more descriptive exception message will be thrown to let you know what actions to take in order to prevent this case.