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
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.
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 ?
Mike, you can see on the screenshot, the node is found by iterating of full tree.
It is not so easy but I'll try to make a sample for you. May be i'll find some error or lastest version has some fix. :)
Typed on phone,
Regards,
Roman
Hi Roman,
If you are asking for the Count and still not finding the node you want, the I can only assume that the node with that key doesn't exist in your data source. If it does, then I'd need to see a sample project demonstrating this behavior so I can debug it and see what's going wrong. I don't have any ideas about why that would happen.
Hi Mike,
Unfortunatly I catch this problem too.
Look please on attached screenshot.
I show callstack where the method SelectNode has parameter key that is "31".
Method SelectNode uses property Count for each NodeCollection in the tree via RefreshData().
So all keys should be updated for next actions.
And I use my method GetNodeByKey that should return value from UltraTree.GetNodeByKey("31")
From time to time it works fine. But sometimes it returns null.
On screenshot you can see that node with key is not found by UltraTree.GetNodeByKey("31") but is found by iterate tree.
Have you some ideas about causes? How to avoid this?
Regards
Hi Benoit,
The actual looping through all the nodes in the tree could cause a performance hit up front. The tree defers loading the nodes up front in the first place because retrieving the child nodes from any particular parent node may not be very efficient. A DataSet, for example, has to loop through every row in the child table every time it attempts to get the child rows for any particular parent row.
If you are using an UltraDataSource or another data source that doesn't have to deal with dynamically-changing relational data, then it will probably not be a big deal.
Once the nodes are initially loaded, this should not slow down your application any. On the contrary, it will probably speed things up. The cost of this is that you are using more memory, of course.
sorry for the delay. I finally had the chance to test Mike's proposal and it works fine. I made a small method that loop into all nodes and child nodes of the tree and call the Count method on each. Then I use the GetNodeByKey method and it works. Is this way to do this will slow the tree substantially, especially if the tree contains a lot of nodes ?