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
bulrickAsked:
Who is Participating?
 
ElrondCTCommented:
You don't need to "select" the node in the TreeView. Just add the subnode directly to it:

newMain.Nodes.Add(newMainSub01)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.