Bonjour à tous, voici mon problème :
J'aimerais afficher ceci dans mon TreeView :
Par rapport à ce fichier:
Alors j'ai pondu ce code:
Seulement ça ne fonctionne pas ! :(
J'aimerais afficher ceci dans mon TreeView :
Par rapport à ce fichier:
Code:
# type|Location|name|ID
folder||Settings|Folder_Settings
folder||MyProject|Folder_MyProject
folder|MyProject|My|Folder_My
folder|MyProject/My|Help|Folder_Help
folder|Settings|App|Folder_App
file|MyProject/My|test.vb|File_Test
Alors j'ai pondu ce code:
Code:
Dim lines As String() = _files.Split(vbLf) 'c'est le fichier text de en haut
Dim Folders As New List(Of String)
Dim FoldersWithParents As New List(Of String)
Dim MaxCount As Integer = 0
Dim Files As New List(Of String)
For Each line As String In lines
If line.Split("|").First = "folder" Then
Folders.Add(line)
Else
Files.Add(line)
End If
Next
For Each Folder As String In Folders
Dim data() As String = Folder.Split("|")
If Not data(1) = "" Then
Dim Parents() As String = data(1).Split("/")
If Parents.Count > MaxCount Then
MaxCount = Parents.Count
End If
End If
Next
For invoked_i As Integer = 0 To MaxCount
For i As Integer = 0 To Folders.Count - 1
Dim data() As String = Folders.Item(i).Split("|")
Dim folder_parents() As String = (data(1) & "/").Split("/")
If folder_parents(invoked_i) = "" Then
Dim NewNode As New TreeNode
NewNode.ImageIndex = 0
NewNode.SelectedImageIndex = 0
NewNode.Text = data(2)
NewNode.Tag = data(3)
NewNode.ToolTipText = "folder:" & data(3)
TreeView.Invoke(Sub()
If Not folder_parents(0) = "" Then
If TreeView.GetNodeByFullPath(data(1)) IsNot Nothing Then
TreeView.GetNodeByFullPath(data(1)).Nodes.Add(NewNode)
Else
TreeView.Nodes.Add(NewNode)
End If
Else
TreeView.Nodes.Add(NewNode)
End If
End Sub)
Else
FoldersWithParents.Add(Folders.Item(i))
End If
Next
Folders = FoldersWithParents
Next
Code:
<Extension()> _
Public Function GetNodeByFullPath(ByVal TreeView As TreeView, ByVal FullPath As String) As TreeNode
Dim TreeNode() As TreeNode = TreeView.Nodes.Find(FullPath, True)
If TreeNode.Count > 0 Then
Return TreeNode(0)
Else
Return Nothing
End If
End Function
Seulement ça ne fonctionne pas ! :(