Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6753159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:07:40+00:00 2026-05-26T13:07:40+00:00

am trying to pupulate a treeview nodes base on directory structure like this Dim

  • 0

am trying to pupulate a treeview nodes base on directory structure like this

Dim arrLinks() As String = Split(Url, "/")

For i As Integer = 0 To arrLinks.Length
    If tvwDirs.Nodes.ContainsKey(arrLinks(0)) = False Then
        tvwDirs.Nodes.Add(arrLinks(0), arrLinks(0))
    End If
Next

The above code works for add base/parent node

say i have a urllike this example.com/dir1/dir2/file

in this case, it should create a child node dir2 in parent node dir1

am getting confused add child nodes to the existing nodes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:07:41+00:00Added an answer on May 26, 2026 at 1:07 pm

    The first issue you are going to run into is an exception based on your for statement; you should either change it to:

    For i As Integer = 0 To arrLinks.Length - 1
    

    or, my preference:

    For each nodeKey as String in arrLinks
    

    The next issue is that the Nodes collection does not contain all of the Nodes in the entire tree, it only contains the top level nodes. Each node in this list has its own set of child nodes and each of those children has child nodes, etc.

    This means that as you add each node, you need to keep track of the last parent node and add the next child to that parent node or keep track of the current collection of nodes for the level that you are adding to.

    This will result in code similar to the following (you may need to adjust the class names for NodeCollection and Node and possible the Add statement (don’t remember off the top if add returns a Node or not)):

    Dim arrLinks() As String = Split(Url, "/")
    Dim cNodes as NodeCollection
    
    ' Keep track of the current collection of nodes, starting with the tree's top level collection
    cNodes = tvwDirs.Nodes
    
    For each nodeKey As String in arrLinks
        Dim currentNode as Node
    
        If Not cNodes.ContainsKey(nodeKey) Then
            ' If the key is not in the current collection of nodes, add it and record the resultant record
            currentNode = cNodes.Add(nodeKey, nodeKey)
        Else
            ' Otherwise, record the current node
            currentNode = cNodes(nodeKey)
        End If
        ' Store the set of nodes that the next nodeKey will be added to
        cNodes = currentNode.Nodes
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a treeview like structure from JSON data . Structure
I want a TreeView with checkboxes and I'm trying to follow this tutorial .
I am trying to populate a string with a double value using a sprintf
I'm trying to populate a dictionary dynamically in a for loop like so: pseudo-code
I'm trying to populate a ComboBox programatically. I am creating ComboBoxItems and would like
I am trying to create a treeview dynamically using c# and asp.net. I have
I am trying to create a TreeView from the Silverlight TreeView control. I have
I am trying to populate a treeview using mvvm but the tree does not
I'm trying to create a TreeView which has two levels but I'm getting nowhere.
i'm trying to populate the heap with a string array, but the console gave

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.