Friday, April 17, 2020

VB.Net TreeView Populate and Show which node is selected


Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TreeView1.Nodes.Add("Node 0")
        TreeView1.Nodes.Add("Node 1")
        TreeView1.Nodes.Add("Node 3")
        TreeView1.Nodes(0).Nodes.Add(New TreeNode("Project 1"))
        'Creating child nodes under the first child

        For loopindex As Integer = 1 To 4
            TreeView1.Nodes(0).Nodes(0).Nodes.Add(New _
            TreeNode("Sub Project" & Str(loopindex)))
        Next loopindex
        ' creating child nodes under the root
        TreeView1.Nodes(0).Nodes.Add(New TreeNode("Project 6"))
        'creating child nodes under the created child node

        For loopindex As Integer = 1 To 3
            TreeView1.Nodes(0).Nodes(1).Nodes.Add(New _
            TreeNode("Project File" & Str(loopindex)))
        Next loopindex
    End Sub

    Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
        ' Determine by checking the Node property of the TreeViewEventArgs.  
        MessageBox.Show(e.Node.Text)
    End Sub
End Class

Thanks to:
https://www.tutorialspoint.com/vb.net/vb.net_treeview.htm
https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-determine-which-treeview-node-was-clicked-windows-forms

No comments:

Post a Comment

Cocktail Jazz for Beginners

  https://pianowithjonny.com/piano-lessons/how-to-play-beginner-cocktail-piano-in-3-steps/ https://www.pianogroove.com/jazz-piano-lessons/co...