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://ko.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