The treeview control in VB.net 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
Other People Are Reading
Create a new windows application in Visual Studio with one form.
Drop a TreeView, TextBox and Button onto the form. They will be called "TreeView1," "TextBox1" and "Button1."
Dock TreeView1 to the left-hand side of the form and position the textbox and button to the right of it.
On the "Nodes" property of the Treeview, click to bring up the TreeView Editor and add a "Root node," which will be called "node0."
Add this code to the click event of the button:
Dim SelectedNode As TreeNode SelectedNode = TreeView1.SelectedNode If SelectedNode Is Nothing Then TreeView1.Nodes.Add(TextBox1.Text) Else SelectedNode.Nodes.Add(TextBox1.Text) End If
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.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for