I've assigned keys (strings) to all of my nodes in the tree. Now I would like to retrieve one of these nodes but I am not always certain if the key is in the tree or not. I'm used to using TryGetValue in dictionaries but this dosen't seem to be supported. I don't want to throw a KeyNotFound exception. How do I test if the key is valid? I've tried tree.Nodes.IndexOf("keystring") but it always returns -1.
Thanks that was the problem. In previous tree packages I've had to check every node. I was hoping to make it more efficient than that but didn't realize at first I still had to recurse. Its still more efficient as I don't need to check every node, but still need to do the check once at each level.
Because of the recursive nature of a tree structure, you have to search all Nodes collections recursively. Each UltraTreeNode exposes a Nodes collection, so searching only the UltraTree.Nodes (i.e., root level nodes collection) is not sufficient for your purposes.
Note that the control exposes a GetNodeByKey method, which performs just such a recursive search.
Ok nevermind. Just after I posted I found Nodes.Exists(key). Now this is still returning false so there must be something wrong somewhere else.