A chaque fois qu'on assigne une List au ".DataSource", la propriété ".BindingContext" ajoute un élément à sa liste.
Cet élément contient un champs "dataSourceHashCode" qui correspond au HashCode de la List qu'on obtient avec
la fonction ".GetHashCode".
Je pense qu'à chaque assignement de la propriété ".DataSource", il utilise le HashCode de la List s'il le
trouve dans la liste ".BindingContext()".
On peut y voir un champs ".Position" qui indique je pense l'Index sélectionné.
J'ai filtré la List "Mois", mais évidement comme il crée une autre List elle apparait en "Inconnu" :
Me.ListBox1.DataSource = Mois.Where(Function(i) i.StartsWith("F")).ToList
J'ai écrit ceci pour le visualiser :
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
| Dim propertiesInfo As PropertyInfo()
Dim prop As PropertyInfo
Dim valProp As Object
Dim valDataSourceHashCode As FieldInfo
Dim BD As Object
Dim HashCodeMois As Integer
Dim HashCodeCouleur As Integer
Dim NomListe As String
Dim Position As Integer
Dim Hcode As Integer
HashCodeMois = Mois.GetHashCode
HashCodeCouleur = Couleur.GetHashCode
For Each BD In Me.ListBox1.BindingContext
propertiesInfo = BD.GetType().GetProperties()
For Each prop In propertiesInfo
valProp = prop.GetValue(BD, Nothing)
If prop.Name = "Key" Then
valDataSourceHashCode = valProp.GetType().GetField("dataSourceHashCode", BindingFlags.NonPublic Or BindingFlags.Instance)
Hcode = valDataSourceHashCode.GetValue(valProp)
If Hcode = HashCodeMois Then
NomListe = "Mois"
ElseIf Hcode = HashCodeCouleur Then
NomListe = "Couleur"
Else
NomListe = "Inconnu"
End If
Console.WriteLine("Liste : " & NomListe)
ElseIf prop.Name = "Value" Then
Position = BD.value.target.position
Console.WriteLine("Position : " & Position)
End If
Next prop
Next BD
Console.WriteLine() |
Partager