Results 1 to 2 of 2

Thread: [RESOLVED] Building a treeview VB.Net 2003

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Resolved [RESOLVED] Building a treeview VB.Net 2003

    Hi,
    I have a treeview built, and it works just like I want it. However, I have to "prime" it with the first level of nodes. After that, I go through each first level node and add nodes to it, and add nodes to its nodes, and .... all the way down recursively. This recursive function, AddNodes, receives a node as its input. So, right now its like this:

    BuildTree()
    GrabFirstLevelNodes()

    for each node in tree
    AddNodes(node)

    End Sub

    Is there any way around this, or is my code just going to have to have this ugly GrabFirstLevelNodes sub? I tried to send the tree itself as a node (figured it was worth a shot), but it isn't the right type.

    Any ideas?

    Thanks
    Last edited by 18experience; Dec 28th, 2006 at 03:30 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Building a treeview VB.Net 2003

    Your recursive function should take a TreeNodeCollection as an argument. The Nodes property of the TreeView itself is a TreeNodeCollection, as is the Nodes property of each node. That means that you can pass the Nodes property of the tree itself to the first call and then for each recursive call you pass the Nodes property of a node, e.g.
    VB Code:
    1. PopulateNodeCollection(myTreeView.Nodes)
    VB Code:
    1. Public Sub PopulateNodeCollection(ByVal nodes As TreeNodeCollection)
    2.     'Add nodes here.
    3.  
    4.     For Each node As TreeNode In nodes
    5.         PopulateNodeCollection(node.Nodes)
    6.     Next node
    7. End Sub
    That's a very simple and incomplete example but you get the idea.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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