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

Posted on 2006-05-17
Last Modified: 2010-04-23

   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"


        '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"


      The Output should look similar to this:

       Main Categories
       --Category A

    End Sub
Question by:bulrick
    1 Comment
    LVL 20

    Accepted Solution

    You don't need to "select" the node in the TreeView. Just add the subnode directly to it:



    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now