• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Probably a simple TreeView question about adding a subnode in code ... This is the first time I've used it...


   I want to build a TreeView ( Add nodes)  in code when a Form Opens.  How do I set the selected node = a previously defined node in code.

  Private Sub Create_TreeView()
        ' Adds new node as a child node of the currently selected node.
        Dim newRoot As New TreeNode
        Dim newMain As New TreeNode

        newRoot.Text = "Root"
        newMain.Text = "Main Categories"

        TreeView1.Nodes.Add(newRoot)
        TreeView1.Nodes.Add(newMain)

        'How do I set Selected Node to  "Main Categories"
        ' so that the the next node added is a subNode of "Main Categories"?

        Dim newMainSub01 As New TreeNode
        newMainSub01.Text = "Category A"
        TreeView1.Nodes.Add(newMainSub01)

'==================================

      The Output should look similar to this:

       Root
       Main Categories
       --Category A

    End Sub
0
bulrick
Asked:
bulrick
1 Solution
 
ElrondCTCommented:
You don't need to "select" the node in the TreeView. Just add the subnode directly to it:

newMain.Nodes.Add(newMainSub01)

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now