IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Création d'un object avec 4 données string imbriqué


Sujet :

VB.NET

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mars 2021
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Deux Sèvres (Poitou Charente)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Mars 2021
    Messages : 4
    Par défaut Création d'un object avec 4 données string imbriqué
    Bonjour,
    Cela fait maintenant un moment que je tente plusieurs façon de procéder pour réaliser mon projet mais je but à chaque fois.
    Je souhaiterais créer un object. Il y a 4 données string, projet, nomCarte, reference, amdt.
    il faudrait les ranger de la un peu à la façon d'un xml :
    Exemple :
    Projet =toto
    carte =gg
    Référence =gg32
    Amdt=a
    Référence =gg45
    Amdt=c
    Amdt=a
    Carte=hh
    Référence =gg12
    Amdt=f
    Carte =lh
    Référence =gg11
    Amdt=a
    Référence =gg15
    Amdt=a
    Amdt=j
    Référence =gg12
    Amdt=j
    La ou je bloque c'est qu'il faudrait que Quand je sélectionne un projet cela me retourne une liste des cartes associeées.
    si je prend l'exemple ci dessus, si je récupère toto retourne toute le carte puis si je sélectionne une carte ex hh retourne toute les référence ex gg12puis même chose pour Amdt.
    Le but est de pouvoir les mettres dans des listesbox imbriqué exemple : si j'ai choisi toto
    La liste box carte sera mit à jour etc.....

    J'ai déjà tenté plusieurs choses qui fonctionnais mais j'arrive vitte à des usines à gaz.
    Je suis débutant et je ne maîtrise pas encore toutes les subtilitées de la poo.

    L'idée est après est de stoquer les objects créer dans un fichier XML cripter. Après ça c'est uen autre histoire.

    Pouvez vous me guider svp je vous remercie d'avance.

  2. #2
    Membre Expert Avatar de Thumb down
    Homme Profil pro
    Retraité
    Inscrit en
    Juin 2019
    Messages
    1 561
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Juin 2019
    Messages : 1 561
    Par défaut
    Bonjour,
    Soit tu ajoutes une classe à ton projet qui contient les propriétés projet, nomCarte, reference, amdt. Que tu gèrera dans le code principal via un dictionnarry.

    Soit tu ajoutes une structure à ton projet avec projet, nomCarte, reference, amdt en variable. Que tu gèrera dans ton programme principal comme un array !
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Obj(lndex).projet="toto"
    Obj(lndex).nomCarte="titi"
    Obj(lndex).reference,="tutu"
    Obj(lndex).amdt="tata"

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mars 2021
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Deux Sèvres (Poitou Charente)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Mars 2021
    Messages : 4
    Par défaut
    Merci je vais déjà tester ca, v'javais déjà essayé avec une structure mais pas une structure tableau au sein de la class.
    Par je ne vois pas encore les données vont s'imbriquer dans la class mère.

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2006
    Messages
    505
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Février 2006
    Messages : 505
    Par défaut Le datatable
    Pour ma part, j'aime bien travailler avec les data tables. De la on peut faire des requêtes.
    Je me réfère souvent à ce tuto https://plasserre.developpez.com/cours/vb-net/ de Philippe Lasserre

    bonne codage!

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mars 2021
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Deux Sèvres (Poitou Charente)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Mars 2021
    Messages : 4
    Par défaut SUITE
    Merci pour les infos j'ai testé plusieurs chose mais je galère toujours autant .
    j'ai l'impression de faire des usines à gaz .

    j'ai pensé aux treedNode mais je sais pas si mon idée est bien ou trop compliqué

    j'ai créer une class qui contient plusieurs projets

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    Public Class PROJETS
     
        Private _ListProjets As New List(Of PROJET)
        Private _num As Integer
        Private ad As New AccesAuxDonnees
     
        Public Sub New()
            Me.LoadData()
        End Sub
     
        Public Sub LoadData()
            ad.LoadData(_ListProjets)
            _num = 0
        End Sub
     
        Public Sub SaveData()
            ad.SaveData(_ListProjets)
        End Sub
     
        Public Function ProjetPointé() As PROJET
            If _ListProjets.Count <> 0 Then
                If _num < _ListProjets.Count Then
                    Return _ListProjets.Item(_num)
                Else
                    Return Nothing
                End If
            Else
                Return Nothing
            End If
        End Function
     
        Public Sub AjouterProjet(ByVal l As PROJET)
            _ListProjets.Add(l)
        End Sub
     
        Public Sub SuprimerProjet()
            _ListProjets.RemoveAt(_num)
        End Sub
     
        Public Sub MajProjet(ByVal l As PROJET)
            _ListProjets.Item(_num) = l
        End Sub
     
        Public Sub ProjetSuivant()
            If _num < _ListProjets.Count Then
                _num += 1
            End If
        End Sub
     
        Public Sub ProjetPrécedent()
            If _num > 0 Then
                _num -= 1
            End If
        End Sub
     
        Public Sub PromierProjet()
            _num = 0
        End Sub
     
        Public Sub DernierProjet()
            _num = _ListProjets.Count - 1
        End Sub
     
     
     
     
    End Class

    celle-ci contient une Liste de class Projet la ça commence déjà à être l'usine

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
     
    Public Class PROJET
     
        Private _ProjetNode As New TreeNode
        Private _Nom As String
        Private _PositionDesignation As Integer
        Private _PositionReference As Integer
        Private _PositionAmdt As Integer
     
     
    #Region "Constructeur"
     
        Sub New(ByVal PremierNom As String)
            _Nom = PremierNom
            _ProjetNode.Text = PremierNom
            PositionDesignation = 0
            PositionReference = 0
            PositionAmdt = 0
        End Sub
     
        Sub New()
     
            _Nom = "Nothing"
            _ProjetNode.Text = "Nothing"
            PositionDesignation = 0
            PositionReference = 0
            PositionAmdt = 0
        End Sub
     
    #End Region
     
    #Region "propriété"
     
        Public Property PositionDesignation() As String
            Get
                Return _PositionDesignation
            End Get
            Set(ByVal value As String)
                _PositionDesignation = value
            End Set
        End Property
     
        Public Property PositionReference() As String
            Get
                Return _PositionReference
            End Get
            Set(ByVal value As String)
                _PositionReference = value
            End Set
        End Property
     
        Public Property PositionAmdt() As String
            Get
                Return _PositionAmdt
            End Get
            Set(ByVal value As String)
                _PositionAmdt = value
            End Set
     
        End Property
     
        Public Property Nom() As String
            Get
                Return _Nom
            End Get
            Set(ByVal value As String)
                _ProjetNode.Text = value
                _Nom = value
            End Set
        End Property
     
        Public ReadOnly Property EtiquetteNode As TreeNode
            Get
                Return _ProjetNode
            End Get
        End Property
     
    #End Region
     
     
    #Region "Méthode"
     
    #Region "Designation"
     
        Public Sub AjouterDesignation(ByVal val As String)
            _ProjetNode.Nodes.Add(New TreeNode(val))
        End Sub
     
        Public Function NbDesignation()
            Return _ProjetNode.Nodes.Count - 1
        End Function
     
        Public Sub DesignationSuivante()
            If _PositionDesignation < _ProjetNode.Nodes.Count - 1 Then
                _PositionDesignation += 1
            End If
        End Sub
     
        Public Sub DesignationPrecedente()
            If _PositionDesignation > 0 Then
                _PositionDesignation -= 1
            End If
        End Sub
     
        Public Sub PremiereDesignation()
            _PositionDesignation = 0
        End Sub
     
        Public Sub DerniereDesignation()
            _PositionDesignation = _ProjetNode.Nodes.Count - 1
        End Sub
     
        Public Sub EffacerDesignation()
            If _ProjetNode.Nodes.Count > 0 Then
                _ProjetNode.Nodes.RemoveAt(_PositionDesignation)
                DerniereDesignation()
            End If
        End Sub
     
        Private Function DesignationPointé() As TreeNode
            If _ProjetNode.Nodes.Count <> 0 Then
                If _PositionDesignation < _ProjetNode.Nodes.Count Then
                    Return _ProjetNode.Nodes(_PositionDesignation)
                Else
                    Return Nothing
                End If
            Else
                Return Nothing
            End If
        End Function
     
        Public Function DesignationText() As String
            If Not DesignationPointé() Is Nothing Then
                Return DesignationPointé.Text
            Else
                Return ""
            End If
        End Function
     
        Public Sub RenommerDesignation(ByVal val As String)
            If Not DesignationPointé() Is Nothing Then
                DesignationPointé.Text = val
            End If
        End Sub
     
    #End Region
     
    #Region "Reference"
     
        Public Sub AjouterReference(ByVal val As String)
     
            If NbDesignation() = -1 Then
                AjouterDesignation("Nothing")
                DerniereDesignation()
                _ProjetNode.Nodes(_PositionDesignation).Nodes.Add(New TreeNode(val))
            Else
                _ProjetNode.Nodes(_PositionDesignation).Nodes.Add(New TreeNode(val))
            End If
     
        End Sub
     
        Public Function NbReference()
            Return _ProjetNode.Nodes(_PositionDesignation).Nodes.Count - 1
        End Function
     
        Public Sub ReferenceSuivante()
            If _PositionReference < _ProjetNode.Nodes(_PositionDesignation).Nodes.Count - 1 Then
                _PositionReference += 1
            End If
        End Sub
     
        Public Sub RreferencePrecedente()
            If _PositionReference > 0 Then
                _PositionReference -= 1
            End If
        End Sub
     
        Public Sub PremiereReference()
            _PositionReference = 0
        End Sub
     
        Public Sub DerniereReference()
            _PositionReference = _ProjetNode.Nodes(_PositionDesignation).Nodes.Count - 1
        End Sub
     
        Public Sub EffacerReference()
            If _ProjetNode.Nodes(_PositionDesignation).Nodes.Count > 0 Then
                _ProjetNode.Nodes(_PositionDesignation).Nodes.RemoveAt(_PositionReference)
                DerniereReference()
            End If
        End Sub
     
        Private Function ReferencePointé() As TreeNode
            If Not NbDesignation() = -1 Then
                If _ProjetNode.Nodes(_PositionDesignation).Nodes.Count <> 0 Then
                    If _PositionReference < _ProjetNode.Nodes(_PositionDesignation).Nodes.Count Then
                        Return _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference)
                    Else
                        Return Nothing
                    End If
                Else
                    Return Nothing
                    End
                End If
            Else
                Return Nothing
            End If
        End Function
     
        Public Function ReferenceText() As String
            If Not ReferencePointé() Is Nothing Then
                Return ReferencePointé.Text
            Else
                Return ""
            End If
        End Function
     
        Public Sub RenommerReference(ByVal val As String)
            If Not ReferencePointé() Is Nothing Then
                ReferencePointé.Text = val
            End If
        End Sub
     
    #End Region
     
    #Region "Amdt"
     
        Public Sub AjouterAmdt(ByVal val As String)
     
            If NbDesignation() = -1 Then
                AjouterDesignation("Nothing")
                DerniereDesignation()
                If NbReference() = -1 Then
                    AjouterReference("Nothing")
                    DerniereReference()
                    _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.Add(New TreeNode(val))
                End If
            Else
                _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.Add(New TreeNode(val))
            End If
     
        End Sub
     
        Public Function NbAmdt()
            Return _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.Count - 1
        End Function
     
        Public Sub AmdtSuivant()
            If _PositionAmdt < _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.Count - 1 Then
                _PositionAmdt += 1
            End If
        End Sub
     
        Public Sub AmdtPrecedent()
            If _PositionAmdt > 0 Then
                _PositionAmdt -= 1
            End If
        End Sub
     
        Public Sub PremierAmdt()
            _PositionAmdt = 0
        End Sub
     
        Public Sub DerniereAmdt()
            _PositionAmdt = _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.Count - 1
        End Sub
     
        Public Sub EffacerAmdt()
            If _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.Count > 0 Then
                _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.RemoveAt(_PositionAmdt)
                DerniereAmdt()
            End If
        End Sub
     
        Private Function AmdtPointé() As TreeNode
            If Not NbDesignation() = -1 Then
                If _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.Count <> 0 Then
                    If _PositionAmdt < _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes.Count Then
                        Return _ProjetNode.Nodes(_PositionDesignation).Nodes(_PositionReference).Nodes(_PositionAmdt)
                    Else
                        Return Nothing
                    End If
                Else
                    Return Nothing
                    End
                End If
            Else
                Return Nothing
            End If
        End Function
     
        Public Function AmdtText() As String
            If Not AmdtPointé() Is Nothing Then
                Return AmdtPointé.Text
            Else
                Return ""
            End If
        End Function
     
        Public Sub RenommerAmdt(ByVal val As String)
            If Not AmdtPointé() Is Nothing Then
                AmdtPointé.Text = val
            End If
        End Sub
     
    #End Region
     
     
    #End Region
     
     
     
    End Class
    tout le reste est piloté dans la class FORM ici pas d'interet de vous la montrer.

    j'ai aussi tenté de sauvegarder le tout dans un fichier XML pour pouvoir réouvrir la list des projets mais je n'y arrive pas
    car je ne sais pas comment décomposer la LIST des treeNode qui est une variable privé de projet


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Imports System.Xml.Serialization
    Imports System.IO
    Public Class AccesAuxDonnees
     
     
        Public Sub SaveData(ByVal lut As Collections.Generic.List(Of PROJET))
            ' Déclaration
     
     
            Dim serialXMLU As Xml.Serialization.XmlSerializer = Nothing
     
            Dim streamIO As StreamWriter = Nothing
            Try
     
     
                serialXMLU = New Xml.Serialization.XmlSerializer(GetType(Collections.Generic.List(Of PROJET)))
     
                streamIO = New StreamWriter("MesProjets.Xml")
     
                serialXMLU.Serialize(streamIO, lut)
     
     
            Catch ex As Exception
                ' Propager l'exception 
                Throw ex
            Finally
                ' En cas d'erreur, n'oubliez pas de fermer le flux en écriture si ce dernier est toujours ouvert
                If streamIO IsNot Nothing Then
                    streamIO.Close()
                End If
            End Try
        End Sub
     
     
     
        Public Sub LoadData(ByRef list As Collections.Generic.List(Of PROJET))
            ' Déclaration
            Dim streamIO As StreamReader = Nothing
            Dim serialXML As Xml.Serialization.XmlSerializer = Nothing
            Try
                ' Tester l'existence du fichier
                If System.IO.File.Exists("MesProjets.Xml") = True Then
                    serialXML = New Xml.Serialization.XmlSerializer(GetType(Collections.Generic.List(Of PROJET)))
                    ' Ouverture d'un flux en lecture sur le fichier XML des contacts
                    streamIO = New StreamReader("MesProjets.Xml")
                    ' Désérialisation de la liste
                    list = CType(serialXML.Deserialize(streamIO), Collections.Generic.List(Of PROJET))
                End If
            Catch ex As Exception
                ' Propager l'exception
                Throw ex
            Finally
                ' En cas d'erreur, n'oubliez pas de fermer le flux en lecture si ce dernier est toujours ouvert
                If streamIO IsNot Nothing Then
                    streamIO.Close()
                End If
            End Try
        End Sub
     
     
     
     
     
    End Class


    quelqu'un peux me dire si je me complique ? si il y a plus simple ?

  6. #6
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    Bonjour

    Tu as une structure hiérarchique dite aussi arborescente ou dite aussi d'arbre (renversé avec les feuilles en bas) :
    code exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    Public Class ItemA 'racine de l'arbre
        Public ListItemB As List(Of ItemB) ' descendants ou  enfants
    End Class
    Public Class ItemB
        Public ListItemC As List(Of ItemC)
    End Class
    Public Class ItemC
        Public ListItemD As List(Of ItemD)
    End Class
    Public Class ItemD 'element feuille ou dernier descendant
     
    End Class
    Elle est gerée dans une "vue" winform par le control TreeView.
    Sauf que dans l'exemple precedent le class List(of T) ne perment pas de retrouver un element par son index:
    code exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    dim it  as ItemB = instanceItemA.ListItemB(3)
    Pour remédier à cet inconvénient et accéder par "NOM"(en fait une clé unique qui n'admet pas des doublons) et aussi par INDEX ,il est préférable d'utiliser une collection dérivée du class KeyedCollection(Of TKey ,TItem), TKey étant la clé.

    Moyennant cet aménagement voici un exemple code qui construit ta liste de projets,cartes ,references et tes fameux "amdt", puis les affiche dans un control TreeView.
    un click sur "node" du TV affiche le "parent" et ses descendants .
    A toi d'jouter d'autres fonctionnalités (ajout ,suppression, modification ,interactif aux collections )
    code behind.vb des class:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Public Class Projet
        Public Property Designation() As String= Nothing
        Public Property Cartes() As CarteCollection 'le keyedcollection.idem pour les autres class
     
        Public Sub New()
            Cartes = New CarteCollection()
        End Sub
        Public Sub New(pdesignation As String)
            Me.New()
            Designation = pdesignation
        End Sub
     
    End Class
    Public Class Carte
        Public Property Designation() As String= Nothing
        Public Property References() As ReferenceCollection
        Public Sub New()
            References = New ReferenceCollection
        End Sub
        Public Sub New(pdesignation As String)
            Me.New()
            Designation = pdesignation
     
        End Sub
     
    End Class
    Public Class Reference
        Public Property Designation() As String= Nothing
        Public Property Amdts() As AmdtCollection
     
        Public Sub New()
            Amdts = New AmdtCollection()
     
        End Sub
        Public Sub New(pdesignation As String)
            Me.New()
            Designation = pdesignation
     
        End Sub
    End Class
    Public Class Amdt
        Public Property Designation() As String = Nothing
        Public Sub New()
        End Sub
        Public Sub New(pdesignation As String)
            Me.New()
            Designation = pdesignation
     
        End Sub
    End Class
    code behind.vb des collections dérivées pour chacun des class précédents (à regrouper dans un fichier de class dénommé Collections.vb)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Imports System.Collections.ObjectModel
     
    Public Class ProjetCollection
        Inherits KeyedCollection(Of String, Projet)
        Public Sub New()
            MyBase.New(Nothing, 0)
        End Sub
        Protected Overrides Function GetKeyForItem(item As Projet) As String
            Return item.Designation
        End Function
    End Class
    Public Class CarteCollection
        Inherits KeyedCollection(Of String, Carte)
        Public Sub New()
            MyBase.New(Nothing, 0)
        End Sub
        Protected Overrides Function GetKeyForItem(item As Carte) As String
            Return item.Designation
        End Function
    End Class
    Public Class ReferenceCollection
        Inherits KeyedCollection(Of String, Reference)
        Public Sub New()
            MyBase.New(Nothing, 0)
        End Sub
        Protected Overrides Function GetKeyForItem(item As Reference) As String
            Return item.Designation
        End Function
    End Class
     
    Public Class AmdtCollection
        Inherits KeyedCollection(Of String, Amdt)
        Public Sub New()
            MyBase.New(Nothing, 0)
        End Sub
        Protected Overrides Function GetKeyForItem(item As Amdt) As String
            Return item.Designation
        End Function
    End Class
    code behind.vb du user form de test:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    bon code...

Discussions similaires

  1. Réponses: 3
    Dernier message: 01/05/2020, 11h21
  2. [XL-2010] Création d'un graphe avec des données dynamiques
    Par ultrabody dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 05/02/2016, 12h31
  3. Réponses: 1
    Dernier message: 02/07/2015, 11h55
  4. [Data] Création d'une session avec des données du runtime
    Par NeedToHelp dans le forum Spring
    Réponses: 2
    Dernier message: 17/07/2009, 11h13
  5. [MySQL] Création d'un tableau avec les données d'une base de données
    Par opeo dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 02/04/2009, 20h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo