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
It's hard to say what's going on there without seeing the code in action. If GetNodeByKey is returning the wrong node, then the only explaination I can think of is that you are somehow mistaken about the Key's you are assigned to your nodes. Or maybe there's some kind of timing issue and you are asking for the node and getting it before it gets removed from the collection.
Also... there is no Exists method on a node, so the code you posted here can't be right - unless you added an extender method or something. Or maybe that's just a typo and your actual code is:
if(!e.Node.Nodes.Exists("parts"))
If so, then again, I can't think of any reason why this method would not work correctly. But keep in mind that the keys of nodes must be unique across the entire tree - not just the collection they are in. So it's entirely possible for this line of code to return false (indicating that the Nodes collection of the particular parent node does not contain a node with that key) but for the subsequent adding of a node with that key to fail because some other node under some other parent or at the root level somewhere else in the tree exists with the same key.
It is not that is returning the wrong node…it is just returning a 'version' of that node that does not to seem to belong to the collection based on what I see when I inspect the object.
That is the code on the exists…it is taken from the even argument of the AfterExpand method of the tree.
This is a very large product so what is the best way I can show this to you guys? I pay for support so should I open a ticket? Would I be able to show someone on a goto meeting tip thing? I can maybe make a movie too and upload it?
Thanks,Mele
e.Nodes actually..yes that is a typo!
Hello Mele,
We are still following this forum thread.
Please feel free to let us know if you still have any questions on this matter.
Yes still having this issue. Just got involved in some other projects.
I am in the tree's after expand...I want to refresh the child nodes underneath.
tree looks like:
Parent
Child
code looks like
Boolean b = e.TreeNode.Nodes.Exists("child");
//b evaluates false
if(!e.TreeNode.Nodes.Exists("child"))
e.TreeNode.Nodes.Add("child","child"); //FAILS WITH KEY ALREADY EXISTS
We are using 14.1.6.0
Thanks,
Mele
Here are some pics.
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