I'm trying to filter the nodes in my tree by evaluating a condition on each one and setting its Visible property to false if it doesn't match. However, when I try to hide the (single) selected node, I get the error message "The ActiveNode can only be set to a node that belongs to this control."
Since I can't not have an ActiveNode, how can I make this work?
Thanks, Aaron
Hi Aaron,
I tested this out with 2 different data sources, a BindingList and an UltraDataSource, just in case it did matter, but I still don't get any exceptions.
I'm attaching my sample project here (based on your code) so you can try it out and see if the exception happens on your machine. If it does, then my guess is that you are using an old version of the controls and you just need to get the latest service release.
Here's some code that reproduces the error:
public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { Bind(); }
private void button1_Click(object sender, EventArgs e) { this.ultraTree1.BeginUpdate(); Bind(); this.ultraTree1.ActiveNode.Visible = false; this.ultraTree1.EndUpdate(); }
private void Bind() { CustomerCollection customers = DataManager.GetCustomers(1); this.ultraTree1.DataSource = customers; } }
DataManager.GetCustomers(1) returns a collection of Customer objects, but it doesn't seem to matter what the structure of this data is - the important part is the sequence of operations in the button handler.
Aaron
The rebind-and-filter operation is between calls to BeginUpdate and EndUpdate to prevent visual artifacts. If I remove those calls, there's no exception. This error has been reported many times before - search for "The ActiveNode can only be set to a node that belongs to this control" and you'll find lots of references to it, but nobody seems to have an actual resolution.
Currently, I'm just eating the exception, which seems to work OK, but I don't know what the implications of that might be.
Seems to be a bit more complicated than I originally stated it. I don't have a simple reproducible case yet, but it seems to have to do with hiding a bunch of nodes, rebinding the tree, then hiding nodes again. It may have something to do with what happens to ActiveNode when I rebind the tree?
I was not able to reproduce the problem you describe here with a simple test; I set the Visible property to false for the only member of the SelectedNodes collection, and did not get the error you cited here. If possible please attach a sample project demonstrating the problem here and we will investigate further.