Forum: VB.NET |
Thema:
Re: TreeView mit Daten einer Acces Tabelle füllen |
Von:
Theo Driemann (
09.02.2006 00:03) |
I found the solution. This code suppose to work
VB.NET / Framework 2.0
This code is not my mental extract but it works. If not please let me know.
Public Class FillTreeView
Public Sub initilizeFillTreeView()
Dim i As Integer
Dim arrNames(8) As String
Dim node As TreeNode
arrNames(0) = "C:\Musik\Phil Collins\Live"
arrNames(1) = "C:\Musik\Phil Collins\Live\Lamp Lies down"
arrNames(2) = "C:\Dokumentation\Musik\Phil Collins"
arrNames(3) = "C:\Phil Collins\Dokumentation\Musik"
node = Form1.TreeView1.Nodes.Add(0, "Root")
For i = 0 To 3
addNode(node, arrNames(i))
Next
End Sub
Public Sub addNode(ByVal node As TreeNode, ByVal name As String)
Dim curNode As TreeNode
Dim subString() As String = name.Split("\")
Dim curName As String = subString(0)
Dim nextName As String = ""
Dim i As Integer
subString.Length > 1 Then
For i = 1 To subString.Length - 1
nextName &= subString(i) & "\"
Next
nextName = nextName.TrimEnd("\")
End If
Dim exsist As TreeNode = New TreeNode("")
For Each curNode In node.Nodes
If curNode.Text = curName Then
exsist = curNode
End If
Next
If exsist.Text <> "" Then
addNode(exsist, nextName)
Else
Dim newNode As TreeNode = New TreeNode(curName)
node.Nodes.Add(newNode)
If nextName <> Nothing Then
addNode(newNode, nextName)
End If
End If
End Sub
End Class
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!