Results 1 to 3 of 3

Thread: Crawling A Treeview From A Selected Node

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    11

    Question Crawling A Treeview From A Selected Node

    Hi,

    Does anyone know how to crawl a treeview from selected node? The following code doesn’t work,

    Dim tn As TreeNode

    For Each tn In tv.SelectedNode.Nodes
    MsgBox(tn.Text)
    Next

    It doesn’t give me the child nodes. Does anyone out there know how to do this?

    Thank you,
    Bob

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The Nodes collection are the children or should be. You'd have to use a recursive function to get all levels though.

    VB Code:
    1. 'I didn't test this code
    2.  
    3. 'call it somewhere and pass the selectednode like this
    4. ShowKids(tv.SelectedNode)
    5.  
    6. Public Sub ShowKids(ByVal Nodx As TreeNode)
    7.    Dim tn As TreeNode
    8.  
    9.    For Each tn In Nodx.Nodes
    10.       MsgBox(tn.Text)
    11.       ShowKids(tn) 'here it calls itself to handle any children of this child (recursive)
    12.    Next
    13. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    11

    Works

    Works...Thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width