Treeview Find Node Issue - VB2005

S

Sergio Terenas

Hi all,

I've a Treeview control in a form load with 600 nodes. Each node has a text and tag associated to it at the time I add it.

I need to find a node by either the text or the tag, make it the SelectedNode and then make sure it's visible on the tree.

I've been playing with the treeview's properties/methods but I think I got stuck.

Dim aKey As String = txtKey.Text
Dim a As Integer
a = treeview1.Nodes.IndexOfKey(aKey)
If tvApoderados.Nodes.ContainsKey(aKey) Then
MsgBox("yes
Else
MsgBox("No")
End If

BTW, I'm sure the value of txtKey.text exists in the treeview nodes. Could anyone please provide a quick example on how to find/select/show a particular node in VB2005 ?

Thanks,

Sergio Terenas
 
H

Herfried K. Wagner [MVP]

Sergio Terenas said:
I've a Treeview control in a form load with 600 nodes. Each node has a
text and tag associated to it at the time I add it.

I need to find a node by either the text or the tag, make it the
SelectedNode and then make sure it's visible on the tree.

'TreeView.Nodes' only contains the nodes at root-level. One solution is to
add all the nodes to a 'Hashtable' using the name as key and the node as
value.
 
S

Sergio Terenas

Thanks Herfried for your prompt reply, I forgot to mention those are the
ones I need to find. Only root nodes, no child nodes.
ST
 

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