Bonjour,
Est ce que quelqu’un pourrait m’aider à comprendre le comportement de ListIndex ?
Voir le fichier joint :
J’ai créé un UserForm avec 5 ListBox vides.
Je souhaite initialiser cet UserForm, avant de pouvoir l’utiliser, en affectant à chaque ListBox la même liste de choix mais en sélectionnant au depart une valeur différente dans chaque List Box.
D’où le code :
Public LISTEx() As Variant
Public NBx As Integer
Sub Runinit()
init
initUF
End Sub
Sub init()
NBx = 6
ReDim LISTEx(1 To NBx)
LISTEx(1) = "A"
LISTEx(2) = "B"
LISTEx(3) = "C"
LISTEx(4) = "D"
LISTEx(5) = "E"
LISTEx(5) = "F"
End Sub
Sub initUF()
UserForm1.ListBox1.List = LISTEx
UserForm1.ListBox2.List = LISTEx
UserForm1.ListBox3.List = LISTEx
UserForm1.ListBox4.List = LISTEx
UserForm1.ListBox5.List = LISTEx
UserForm1.ListBox1.ListIndex = 0
UserForm1.ListBox2.ListIndex = 1
UserForm1.ListBox3.ListIndex = 2
UserForm1.ListBox4.ListIndex = 3
UserForm1.ListBox5.ListIndex = 4
UserForm1.Show
End Sub
Lorsque j’active le UserForm, j’ai bien les 5 ListBox remplies avec la bonne valeur sélectionnée,
mais par contre, si je veux utiliser la valeur ou le texte de la Listbox (UserForm1.ListBox1 tout court, ou UserForm1.ListBox1.Value, ou ListBox1.Text par exemple), pour certaines ListBox on a bien en retour la bonne valeur mais pour d’autres, il n’y a rien …
Comment cela s’explique t’il ?....
Merci d'avance !