Solved

How to Quickly Find a TreeNode

Posted on 2006-11-01
1
292 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
1 Comment
 
LVL 10

Accepted Solution

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now