convertir une Collection VB6 et VB.net
bonsoir a tous,
je viens du VB6 et j'ai eu du mal a cree une Collection (l'aide et pas explicite).
Donc j'ai réussi de créer une collection, mais je ne comprend pas comment je peux identifier un Item de la collection par un N°unique invariable.
En VB 6 j'utilisais
Code:
1 2
|
mCollection.Add objNewMember, objNewMember.TPrCelNumAuto & cstKeyColcTPrColCel |
TPrCelNumAuto : un N° auto d'une Base de donnéecstKeyColcTPrColCel : une Chaine de Carractere....
En VB.net j'ai réussi de crée une collection ::yaisse2:
Code:
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
|
Public Class cTPrCols
Implements System.Collections.IEnumerable
Implements System.Collections.IEnumerator
Private marayTPrColsLstKeyPri As Array
Private mCollection As System.Collections.Generic.List(Of cTPrCol)
Private mPosition As Integer = -1
Private mlinkcTPrCol As cTPrCol
Sub New()
mCollection = New System.Collections.Generic.List(Of cTPrCol)
mlinkcTPrCol = New cTPrCol
mPosition = -1
End Sub
Sub New(ByVal obValue As cTPrCol)
mlinkcTPrCol = cTPrCol
mPosition = -1
End Sub
Protected Overrides Sub Finalize()
mCollection = Nothing
mlinkcTPrCol = Nothing
End Sub
Public Function Add(ByVal obAjouter As cTPrCol) As cTPrCol
mCollection.Add(obAjouter)
Add = obAjouter
End Function
Public Sub Reset() Implements System.Collections.IEnumerator.Reset
mPosition = -1
End Sub
Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
GetEnumerator = mCollection.GetEnumerator
End Function
Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
mPosition = mPosition + 1
End Function
End Class |
:oops: Comment je peux appeller un Objet dans la collection a l'aide du N° auto (par exemple) ?
Je pourrais a chaque fois parcourir la collection et verifier les N° auto de chaque objet :( j'ai l'impression d'etre un boullet en faisant ca.
il y a sans doute une autre solution : peu etre lorsque j'ajoute un objet a la collection je pourrais inseret un truc qui serait l'identiant unique !!! et je pourrais rapeller cette objet avec cette identifiant !!8-)
Enfin, voila , merci de votre aide:king: