Hi,
It is hard to explain this issue but I will give it a shot.
I have some nodes like this that i build dynamically
All Items
Test1
Parts
Part1
Part2
Part3
A user can click on Part2 and delete. We call ActiveNode.Remove(). We then set the active node to the parent by saying Tree.ActiveNode to the Test1 node.
I collapse the Test1 Node.
On the before expand method we have a method that builds the child nodes. So the first thing it does is
e.TreeNode.Nodes.Clear();
Then I check for the existence of that Parts node. If it was not there for some reason we rebuild it (because if I was expanding from the root node it would not be there).
if(!e.Node.Exists("parts"))
{
UltraTreeNode n = e.Nodes.Add("parts");///ERROR
}
I get an error on that line that it already exists. But the exists returned false! Furthermore if i do this
UltraTreeNode n = treeView.GetNodeByKey("parts");
it returns a reference…but if you browse that object it is all screwy…for instance 'Parent' is null.
So I read somewhere that you have to call ActiveNode.Dispose()
http://es.infragistics.com/community/forums/t/36985.aspx
I did this but it does not actually remove the node from the UI…stays on the screen. So to get around this after I remove the node I programatically collapse the parent node. This seems to fix the problem but I am not confident now that nodes are properly being disposed off. Plus it is bad for the user to have to expand the node to get back to the parts.
It is further weird because the node being removed is not the node giving us the trouble.
THanks,Mele
Hello Michael,
Thank you for your feedback.
The behavior you are experience is expected behavior. If I understand you correctly here is what you are trying to do and what actually happens:
1 .The user deletes Part2 node by clicking on the node and hit the Delete key. In this moment you are calling ActiveNode.Remove() – please clarify where are you calling this method, is suppose you are calling it in BeforeDelete event. After you remove the ActiveNode, e.g. Part2, you are setting the ActiveNode to the Test1 node and not to the Part2 parent – it is actually the parent of the Test2 parent, as per the structure you have provided in your first post.
2. Then you collapse the active node, Test1. Then, as the user is deleting a node the tree is trying to expand.
3. First the tree expand the most inner node, e.g. Parts node. In BeforeExpand event handler you are clearing all the child nodes of the Parts node and then rebuild them by some your custom method.
4. On next step you are checking this:
if (!e.TreeNode.Nodes.Exists("Parts"))
As you are still in the Parts node this will always return false as you cannot have the child node with same key as its parent node. Actually you cannot have two nodes with same keys in the entire tree. However on this step if you call GetNodeByKey(“Parts”) method of the tree it will return the Parts node as it exists.
5. And finally you are trying to add a new node with Parts key. Actually you are still in the Parts node and you cannot add a node with the same key, so you receive an error.
Please check in BeforeExpand event on which node are you working on. This may help you solve your issue.
If you do need this to be investigated further I will need a sample solution reproducing the behavior you are experience.
Please let me know if you have any additional questions
Actually I found it...ha...luck really. I noticed that the nodes.clear fires the after select event of the tree. I unhooked that event in the after expand and the issue went away. I want to investigate this more because as you can see clearly the collection shows empty when inspecting.
pic 3
pic 2
Here are some pics.