Hi!
I want to use GetNodeByKey to find a node in my tree. I use the InitializeDataNode to assign a unique key value to each node (Tree is data bind).
My problem is when I call the GetNodeByKey. It doesn't find my node until I go in debug mode and find it by myself like (Nodes[0].Nodes[1].Key). After I did that with a watch value in the debugger, then the GetNodeByKey returns the node. It acts like if I had to navigate through the nodes first to tell the tree that the node exists. Why does it acts like act ?
I use UltraTree v.10.2.
Best regards,
Benoit
Did Michael's suggestion help you to resolve the issue you were having? Let me know if you need further assistance with this case.
Michael S.
Hi Benoit,
My guess is that the node you are looking for is a child node and has not been created, yet. When the tree is bound, it will create only the nodes it needs for efficiency. So child nodes do not get created until they are needed, such as when you ask for the Count property of the child nodes collection or when you expand the parent node.
If you want to force all of the nodes in the tree to be loaded, you could recursively loop through every node and ask for it's Node's Count property.
Sorry I was not very clear in my post. I don't call the GetnodeByKey in the initializeDataNode event. I set the key value in this event, but I call GetNodeByKey later.
I'll explain what I need. I programmed a node double click event to open a new form to edit the data contained in my tree. When I save it, I want to refresh the tree with the updated values. It works fine but because I reload all the data in the tree, I lose the focus on the current node. So I want to keep the key of the node and select it again after I refresh the tree. That's why I want to use GetNodeByKey.
Any ideas ?
I think at the point when InitializeDataNode is fired, the node has not yet been added to a collection, so you can't use GetNodeByKey in that event.