VB.Net Add, Edit, Remove TreeView Node

How To Insert Update Delete Selected Node From TreeView In Visual Basic .Net

Add Edit Remove TreeView Node Using VB.Net

In this VB.NET Tutorial we will see How To Add Edit Remove The Selected TreeView Node Using TextBox Value On treeView AfterSelect To Get The Selected Node And 3 Button To Do The Insert, Update, Delete Using Visual Basic.Net Programming Language And Visual  Studio Editor.




Project Source Code:


Public Class Add_Delete_Edit_TreeView_Node
    
    ' button add node
    Private Sub ButtonAddNode_Click(sender As Object, e As EventArgs) Handles ButtonAddNode.Click
        
        Dim node As New TreeNode(TextBox1.Text)
        TreeView1.Nodes.Add(node)

    End Sub

    ' button add child node
    Private Sub ButtonAddChild_Click(sender As Object, e As EventArgs) Handles ButtonAddChild.Click

        ' if a node is selected
        If Not (TreeView1.SelectedNode Is Nothing) Then

            Dim node As New TreeNode(TextBox1.Text)
            TreeView1.SelectedNode.Nodes.Add(node)

        End If

    End Sub

    ' button delete selected node
    Private Sub ButtonDelete_Click(sender As Object, e As EventArgs) Handles ButtonDelete.Click

        If Not (TreeView1.SelectedNode Is Nothing) Then

            TreeView1.SelectedNode.Remove()

        End If

    End Sub

    ' button get selected node text into textbox
    Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect

        TextBox1.Text = TreeView1.SelectedNode.Text

    End Sub

    ' button edit selected node
    Private Sub ButtonEdit_Click(sender As Object, e As EventArgs) Handles ButtonEdit.Click

        TreeView1.SelectedNode.Text = TextBox1.Text

    End Sub
End Class


OutPut:

insert update delete treeview node using vb.net




Share this

Related Posts

Previous
Next Post »