1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
Option Explicit On
Option Strict On
Imports System.IO
Public Class ExpTree
Inherits System.Windows.Forms.TreeView
Public Sub New()
Me.Sort()
Me.HotTracking = True
Me.HideSelection = False
End Sub
Public Sub ShowTree()
For Each d As DriveInfo In DriveInfo.GetDrives
Me.ShowTree(d.Name)
Next
End Sub
Public Sub ShowTree(ByVal Path As String)
Dim nNode As New TreeNode(Path)
Me.Nodes.Add(nNode)
Me.FillTreeNode(nNode)
End Sub
Public Sub ShowTree(ByVal DriveType As DriveType)
For Each d As DriveInfo In DriveInfo.GetDrives
If d.DriveType = DriveType Then
Me.ShowTree(d.Name)
End If
Next
End Sub
Private Sub FillTreeNode(ByVal dNode As TreeNode)
Try
Dim d As New DirectoryInfo(dNode.FullPath)
For Each di As DirectoryInfo In d.GetDirectories
Dim nNode As New TreeNode(di.Name)
dNode.Nodes.Add(nNode)
nNode.Nodes.Add("")
Next
Catch : End Try
End Sub
Protected Overrides Sub OnBeforeExpand(ByVal e As System.Windows.Forms.TreeViewCancelEventArgs)
Dim n As TreeNode = CType(e.Node, TreeNode)
If n.Nodes(0).Text = "" Then
Me.BeginUpdate()
n.Nodes.Clear()
Me.FillTreeNode(n)
Me.EndUpdate()
End If
MyBase.OnBeforeExpand(e)
End Sub
End Class
|