Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find a node given its key

Status
Not open for further replies.

elquixiote

Technical User
Nov 30, 2002
99
MX
How to find a node given its key

Hi!
Is there a way to locate a node in treeview control for a given node.key?

I already accomplish that using the attached code, but couldn't it be a smarter, elegant efficient solution ?

nodePosition = 0
for i=1 to treeview1.nodes.count
if treeview1.nodes(i).key = TheKey then
nodePosition=i
exit for
endif
next i
if nodePosition=0 then
msgbox "Key doesn't exist"
else
msgbox "The key is in " & nodeposition
endif

Thanks,

ElQuijote


 
Use the "Item" method to extract the node based on it's key.

Example below assumes a node in the treeview1 control has a key called "Test".

Dim MyNode as Node
Set MyNode = TreeView1.Nodes.Item("Test")

And that's all you have to do!

Note that if you use a key that is not found, you will get an error "35601 Element not found", so you will need to put an error trap in for this.

Hope this helped,

Robert
 
Thank you. i'll change my brut force algorithm by line you suggest.

Thanks again ..

ElQuijote
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top