1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
Imports System.Collections.Specialized
Public Class Form1
Private Projets As ProjetCollection
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Projets = New ProjetCollection()
LoadData()
End Sub
Public Sub LoadData()
'Ajout du projet = toto
Projets.Add(New Projet("toto1"))
'Ajout des cartes
Dim arrCartes() As Carte = {New Carte("gg"), New Carte("hh"), New Carte("lh")}
AddCartes(arrCartes, Projets("toto1"))
'Ajout carte
'Carte = gg
'Référence = gg32
'Amdt = a
'Référence = gg45
'Amdt = c
'Amdt = a
AddRef(Projets("toto1").Cartes("gg"), "gg32", New String() {"a"})
AddRef(Projets("toto1").Cartes("gg"), "gg45", New String() {"c", "a"})
'Ajout carte
'Carte = hh
'Référence = gg12
'Amdt = f
AddRef(Projets("toto1").Cartes("hh"), "gg12", New String() {"f"})
'Ajout carte
'Carte = lh
'Référence = gg11
'Amdt = a
'Référence = gg15
'Amdt = a
'Amdt = j
'Référence = gg12
'Amdt = j
AddRef(Projets("toto1").Cartes("lh"), "gg11", New String() {"a"})
AddRef(Projets("toto1").Cartes("lh"), "gg15", New String() {"a", "j"})
AddRef(Projets("toto1").Cartes("lh"), "gg12", New String() {"j"})
'le "populate" ou "peuplement" du TV
TV.BeginUpdate()
TV.Nodes.Clear()
'le parcours des collections doit etre fait par index pour remplir "aisement" le TV
For i As Integer = 0 To Projets.Count - 1
Dim itemProjet As Projet = Projets(i)
TV.Nodes.Add(
New TreeNode(itemProjet.Designation))
For j As Integer = 0 To itemProjet.Cartes.Count - 1
Dim itemCarte As Carte = itemProjet.Cartes(j)
TV.Nodes(i).Nodes.Add(
New TreeNode(itemCarte.Designation))
For k As Integer = 0 To itemCarte.References.Count - 1
Dim itemRef As Reference = itemCarte.References(k)
TV.Nodes(i).Nodes(j).Nodes.Add(
New TreeNode(itemRef.Designation))
For n As Integer = 0 To itemRef.Amdts.Count - 1
Dim itemAmdt As Amdt = itemRef.Amdts(n)
TV.Nodes(i).Nodes(j).Nodes(k).Nodes.Add(
New TreeNode(itemAmdt.Designation))
Next
Next
Next
Next
TV.EndUpdate()
End Sub
Private Sub AddCartes(cartes() As Carte, projet As Projet)
For Each item In cartes
projet.Cartes.Add(item)
Next
End Sub
Private Sub AddRef(carte As Carte, refDesignation As String, AmdtDesignations() As String)
Dim ref As New Reference(refDesignation)
Dim listAmdts() As Amdt = {}
carte.References.Add(ref)
For Each designation As String In AmdtDesignations
ref.Amdts.Add(New Amdt(designation))
Next
End Sub
Private Sub AddAmdt(amdts() As Amdt, reference As Reference)
For Each amdt In amdts
reference.Amdts.Add(amdt)
Next
End Sub
Private Sub TV_NodeMouseClick(sender As System.Object, e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TV.NodeMouseClick
TV.SelectedNode = e.Node
ListBox1.Items.Clear()
ListBox1.Items.Add("parent :" & TV.SelectedNode.Text)
For Each item As TreeNode In TV.SelectedNode.Nodes
ListBox1.Items.Add(" " & item.Text)
Next
End Sub
End Class |
Partager