1
我有一個分隔符分隔路徑的數組:分隔符分隔字符串RadTreeView VB.NET
Dim paths = New List(Of String)() From {
"C:\WINDOWS\AppPatch\MUI\040C",
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727",
"C:\WINDOWS\Microsoft.NET\Framework\addins\MUI",
"C:\WINDOWS\addins",
"C:\WINDOWS\AppPatch",
"C:\WINDOWS\AppPatch\MUI",
"C:\WINDOWS\Microsoft.NET\Framework\MUI\MUI\0409"
}
我想創建一個RadTreeView,這將是這個樣子:
+C:
+Windows
+AppPatch
+addins
+Microsoft.NET
+Framework
...
這是我能夠做到的到現在爲止,但有我丟失的東西:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim paths = New List(Of String)() From {
"C:\WINDOWS\AppPatch\MUI\040C",
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727",
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MUI",
"C:\WINDOWS\addins",
"C:\WINDOWS\AppPatch",
"C:\WINDOWS\AppPatch\MUI",
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MUI\0409"
}
If Not Page.IsPostBack Then
Dim subPathAgg As String
Dim pathSeparator As String = "\"
' For each complete individual path
For Each path As String In paths
subPathAgg = String.Empty
' Fill array of strings with each delimited part
Dim arrFolders As List(Of String) = (path).Split(pathSeparator).ToList
Dim lastNode As RadTreeNode = Nothing
Dim iCount As Integer = 0
'For each one of the folders
For Each folder As String In path.Split(pathSeparator)
subPathAgg += folder & pathSeparator
Dim foundNode As RadTreeNode = RadTreeView1.Nodes.FindNodeByValue(subPathAgg, True)
If foundNode Is Nothing Then
If lastNode Is Nothing Then
lastNode = New RadTreeNode(folder, subPathAgg)
RadTreeView1.Nodes.Add(lastNode)
Else
Dim otherNode = New RadTreeNode(folder, subPathAgg)
lastNode.Nodes.Add(otherNode)
lastNode = otherNode
End If
Else
If foundNode.Text <> folder Then
Dim otherNode = New RadTreeNode(folder, subPathAgg)
foundNode.Nodes.Add(otherNode)
lastNode = otherNode
End If
End If
Next
lastNode = Nothing
Next
End If
End Sub
This is how the TreeView looks like right now