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.

--
Thanks for your help.

Harshad Rathod

Re: Finding an item/node in the treeview by Herfried

Herfried
Thu Dec 02 15:00:44 CST 2004

"Harshad Rathod" <HarshadRathod@discussions.microsoft.com> schrieb:
> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Re: Finding an item/node in the treeview by HarshadRathod

HarshadRathod
Thu Dec 02 17:15:03 CST 2004

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

"Herfried K. Wagner [MVP]" wrote:

> "Harshad Rathod" <HarshadRathod@discussions.microsoft.com> schrieb:
> > 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.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>

Re: Finding an item/node in the treeview by HarshadRathod

HarshadRathod
Thu Dec 02 17:31:03 CST 2004

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

Thanks once again.

"Herfried K. Wagner [MVP]" wrote:

> "Harshad Rathod" <HarshadRathod@discussions.microsoft.com> schrieb:
> > 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.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>

Re: Finding an item/node in the treeview by RobertHarris

RobertHarris
Fri Jan 07 11:51:04 CST 2005

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

"Herfried K. Wagner [MVP]" wrote:

> "Harshad Rathod" <HarshadRathod@discussions.microsoft.com> schrieb:
> > 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.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>