VB.NET Simple TreeView - Add TreeNodes


This is a simple treeview example in vb.net.We see how to add treenodes at three levels.First Node,which is our root node,in this case country.Second level node,in this case Country and finally third-leve node in this case cities,where we add multiple cities.

Public Class Form1

    Dim node As TreeNode

    'ADDING  ROOT NODE
    Private Sub addRootBtn_Click(sender As Object, e As EventArgs) Handles addRootBtn.Click
        TreeView1.Nodes.Clear()

        Dim text As String
        text = TextBox1.Text

        If text IsNot "" Then
            node = TreeView1.Nodes.Add(text)
        End If
        'CLEAR TEXTBOX
        TextBox1.Text = ""
    End Sub

    'ADDING  FIRST LEVEL NODE
    Private Sub AddFirstBtn_Click(sender As Object, e As EventArgs) Handles AddFirstBtn.Click
        TreeView1.Nodes(0).Nodes.Clear()

        Dim text As String
        text = TextBox2.Text

        If text IsNot "" Then
            node = TreeView1.Nodes(0).Nodes.Add(text)
        End If

        'CLEAR TEXTBOX
        TextBox2.Text = ""

    End Sub

    Private Sub addSecondBtn_Click(sender As Object, e As EventArgs) Handles addSecondBtn.Click
        Dim text As String
        text = TextBox3.Text

        If text IsNot "" Then
            node = TreeView1.Nodes(0).Nodes(0).Nodes.Add(text)
        End If

        'CLEAR TEXTBOX
        TextBox3.Text = ""
    End Sub

    'CLEAR
    Private Sub clearBtn_Click(sender As Object, e As EventArgs) Handles clearBtn.Click
        TreeView1.Nodes.Clear()

    End Sub
End Class

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think


Previous Post Next Post