How to use Tree View in Microsoft Visual Basic.Net


In this post, I am going to show you how to use Tree View in Microsoft Visual Basic.Net.For this project you need to place a tree view control from the tool box on the form and place a Button on the form and write the following code in the click event of the button.

To use Tree View in Microsoft Visual Basic.Net first create a new project and a form will be created by default. Now, place a tree view control from the tool box on the form. Also, place a Button on the form as shown in the image and change the text to Create Nodes and write the following code in the form 1 code window.


Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
str = InputBox("Please enter name of the node")
If TreeView1.SelectedNode Is Nothing Then
TreeView1.Nodes.Add(str, str)
Else
TreeView1.SelectedNode.Nodes.Add(str, str)
End If
End Sub
End Class

Now, Press F5 to run the project and click on Button 1 and an input box will appear enter the name of the node and click on OK. A node will be added to tree view and if you select any node and then click on the button and enter another node it will be created under the selected node.
Regards
Keep coding


Comments

Author: Maham Naeem Khan21 Apr 2013 Member Level: Bronze   Points : 0

how to create library system on window form using binary tree



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: