Last active
August 29, 2015 14:17
-
-
Save christherama/8f12493226ebaa25db2e to your computer and use it in GitHub Desktop.
Visual Basic TreeView Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub TvFileNav_BeforeCollapse(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TvFileNav.BeforeCollapse | |
e.Node.Nodes.Clear() | |
e.Node.Nodes.Add("") | |
End Sub | |
Private Sub TvFileNav_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TvFileNav.BeforeExpand | |
' clear the expanding node so we can re-populate it, or else we end up with duplicate nodes | |
e.Node.Nodes.Clear() | |
' Get the directory representing this node | |
Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(e.Node.Tag.ToString) | |
' Add each subdirectory from the file system to the expanding node as a child node | |
For Each subdir As IO.DirectoryInfo In dir.GetDirectories | |
' Declare a child TreeNode for the next subdirectory | |
Dim dirNode As New TreeNode | |
' Store the full path to this directory in the child TreeNode's Tag property | |
dirNode.Tag = subdir.FullName | |
' Set the child TreeNodes's display text | |
dirNode.Text = subdir.Name | |
' Add a dummy TreeNode to this child TreeNode to make it expandable | |
dirNode.Nodes.Add("") | |
' Add this child TreeNode to the expanding TreeNode | |
e.Node.Nodes.Add(dirNode) | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment