Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Quickly Find a TreeNode

Posted on 2006-11-01
1
Medium Priority
?
305 Views
Last Modified: 2010-04-23
Hi I currently search my tree by using a recursive function.

    Public Function FindANodeRecursive(ByVal nodeList As TreeNodeCollection, ByVal myId As Object) As TreeNode
        Dim targetNode As TreeNode = Nothing
        For Each aNode As TreeNode In nodeList

            'searches for Node with matching Id.  the ID is stored in treenode.tag
            If aNode.Tag = myId Then

                Return aNode
                Exit Function

            ElseIf aNode.Nodes.Count > 0 Then

                'if nodes is a folder and has children scan it
                targetNode = Me.FindANodeRecursive(aNode.Nodes, myId)
                If Not targetNode Is Nothing Then
                    Return targetNode
                End If

            End If
        Next

        Return targetNode

    End Function

Something the recursive function is very slow.  Is there a better way of finding a treenode??

 One way I was thinking of was using a hashtable with treenode's tag as the key, and the treenode as the value.  This way I can just search the hashtable to find the right node.    Would this be a good idea? also Is there a treenode added event that can listen to when A treenode is added to my tree??  This way I don't have to go through all my code and adding the new keys each time I add a node.

0
Comment
Question by:OFGemini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
gangwisch earned 1000 total points
ID: 17854424
Dim a As New TreeView
        a.Nodes.Find("nameoftreenode", True)
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question