添加TreeView
控制在窗體上,嘗試這樣的:
Option Explicit
Private Sub Form_Load()
pvAddPath TreeView1, "C:\admin\tester1\project\item1\abc"
pvAddPath TreeView1, "C:\admin\tester1\project\item2\abc"
pvAddPath TreeView1, "C:\admin\tester1\project\item1\def"
pvAddPath TreeView1, "C:\admin\tester1\project3\item2\ghi"
End Sub
Private Sub pvAddPath(oCtl As TreeView, ByVal sPath As String)
Dim lNext As Long
Dim lStart As Long
If oCtl.Nodes.Count = 0 Then
oCtl.Indentation = 0
End If
Do While lStart < Len(sPath)
lNext = InStr(lStart + 1, sPath, "\")
If lNext = 0 Then
lNext = Len(sPath) + 1
End If
On Error Resume Next
If lStart = 0 Then
oCtl.Nodes.Add(, , Left$(sPath, lNext), Left$(sPath, lNext)).Expanded = True
Else
oCtl.Nodes.Add(Left$(sPath, lStart), tvwChild, Left$(sPath, lNext), Mid$(sPath, lStart + 1, lNext - lStart - 1)).Expanded = True
End If
On Error GoTo 0
lStart = lNext
Loop
End Sub
來源
2011-03-02 13:43:49
wqw
感謝。但是,在將每個路徑分成幾個文件夾後,我不知道它屬於哪個父項。另外,如何檢查根目錄是否已經存在 – Lynnooi 2011-03-02 06:38:26