Finding an item/node in the treeview

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the most efficient way to search a node in the treeview. I could not
find any built in method in that control and walking through the tree does
not sound right.
 
Harshad Rathod said:
What is the most efficient way to search a node in the treeview. I could
not
find any built in method in that control and walking through the tree does
not sound right.

You can store keys in the 'TreeNode''s 'Tag' property. Then you can add the
nodes to a 'Hashtable' by using the 'Tag' as key. Later you can easily
lookup the nodes from the hashtable by their key.
 
Thanks Herfried. Not quire familiar with Hashtables in C# but will be able
to figure out. If not, I was thinking of using datastore to keep keyvalues
and handles of treenodes. But your idea sounds more efficient.

Thanks.
Harshad
 
Wow! It was so simple. I am creating some framework for corporate
application. This will come very handy elsewhere too.

Thanks once again.
 
Hello everyone. I'm joing this thread a bit late, but it looks exactly like
what I am struggling with as well. I've seen the hashtable solution
recommended in several places for this problem. Is there some sample code I
can look at that does exactly this with a treeview? I'm not sure what the
code would look like. Do you add the nodes to the hashtable first, and then
to the treeview?

Thank you very much!

Robert Harris
 
Back
Top