Finding an item/node in the treeview

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.
 
H

Herfried K. Wagner [MVP]

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.
 
G

Guest

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
 
G

Guest

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

Thanks once again.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top