จเห็นว่า folder ที่อยู่ใน Eng มันไม่ขึ้นต่อน่ะครับ
Code (VB.NET)
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MdiParent = Form1
Dim rootnode As New TreeNode("E:\Test\TestPath\AOD")
TreeView1.Nodes.Add(rootnode)
FillChildNodes(rootnode)
'lastnode(rootnode)
TreeView1.Nodes(0).Expand()
End Sub
Private Sub FillChildNodes(ByVal node As TreeNode)
Try
Dim dirs As New DirectoryInfo(node.FullPath)
For Each dir As DirectoryInfo In dirs.GetDirectories()
Dim newnode As New TreeNode(dir.Name)
node.Nodes.Add(newnode)
newnode.Nodes.Add("")
Next
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
End Sub
Private Sub treeView1_BeforeExpand(ByVal sender As Object, ByVal e As TreeViewCancelEventArgs)
If e.Node.Nodes(0).Text = "" Then
e.Node.Nodes.Clear()
FillChildNodes(e.Node)
End If
End Sub
Tag : .NET, VBScript, Win (Windows App), VS 2010 (.NET 4.x), Windows
TreeNode rootNode = new TreeNode("E:\Test\TestPath\AOD");
TreeNode engNode = new EngNode("Eng");
TreeNode newNode = new EngNode("New");
rootNode.Nodes.Add(engNode); // E:\Test\TestPath\AOD -> Eng
rootNode.Nodes.Add(New); // E:\Test\TestPath\AOD -> New
engNode.Nodes.Add(newNode ); // E:\Test\TestPath\AOD -> Eng -> New