How to Add Leaf Node to Treeview in Vb.Net Using Textbox

Written by allen stoner
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Add Leaf Node to Treeview in Vb.Net Using Textbox
Computer screen with code on it (ANSI image by DBX60 from

The treeview control in can be used to display hierarchical data on a windows form. The items in the treeview are called "nodes." The top level nodes are "'root nodes," which can have "child nodes." Child nodes can also have child nodes. The last child that has no more child nodes, is called the "leaf node."

Skill level:
Moderately Easy


  1. 1

    Create a new windows application in Visual Studio with one form.

  2. 2

    Drop a TreeView, TextBox and Button onto the form. They will be called "TreeView1," "TextBox1" and "Button1."

  3. 3

    Dock TreeView1 to the left-hand side of the form and position the textbox and button to the right of it.

  4. 4

    On the "Nodes" property of the Treeview, click to bring up the TreeView Editor and add a "Root node," which will be called "node0."

  5. 5

    Add this code to the click event of the button:

    Dim SelectedNode As TreeNode
    SelectedNode = TreeView1.SelectedNode
    If SelectedNode Is Nothing Then
    End If
  6. 6

    Run the program and type something into the textbox and click the button. The text you entered will be added to the treeview as a new child node to the currently selected node.

Tips and warnings

  • You can extend the treeview to display a checkbox next to the items or a picture.

Don't Miss


  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.