How To

How to Add a Node to a TreeView Control in VB.net at Run Time

VB.net
VB.net
Member
By Mike
eHow Community Member
(3 Ratings)

A treeview control is similar to a listbox however it has items called nodes. A treeview control is what you would see in your windows explorer to search directories. Here is how you can add nodes at runtime.

Difficulty: Easy
Instructions

Things You'll Need:

  • VB.net
  1. Step 1

    Open VB.net

  2. Step 2
    New Project
    New Project

    Create a new VB.net project by selecting "File" then selecting "New Project".

  3. Step 3
    Button
    Button

    Add a button to the form. This button will be used to add the node at runtime. The underlying code will be addressed in a later step in this how to article.

  4. Step 4
    Treeview
    Treeview

    Add the treeview control to your form. This is the control you will need to add nodes to.

  5. Step 5
    Click event
    Click event

    Double click on the button control to bring up the button's click event.

  6. Step 6
    Code
    Code

    In the click event we will add nodes to our treeview control with this code:
    TreeView1.Nodes.Add("Item " & TreeView1.Nodes.Count)

    This code says to add a node and name it "Item" and then assign the name with the number of items in the control. This way each item has a different name.

  7. Step 7

    Run the program by pressing the "F5" key on your keyboard.

  8. Step 8
    Final Results
    Final Results

    Click the button a few times to see the nodes added.

Post a Comment

Post a Comment

Have you done this? Click here to let us know.

I Did This

Related Ads

Computers
Alexia Petrakos,

Meet Alexia Petrakos eHow’s Computers Expert.

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US

eHow Computers
eHow_eHow Technology and Electronics