Question

What is the best method to loop through TreeView nodes and retrieve a node based on certain value?

Was it helpful?

Solution

It would more efficient to create something like a Dictionary<string, TreeNode> and add all the nodes in it. This of course must be done at the start of the form or whenever you add new tree nodes. The dictionary key can be anything e.g TreeNode Text or business object associated with the node.

You won't need to traverse through all the nodes - just use the search criteria (key) and retrieve the node.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top