Bonjour,

Lors de la sélection d'une des lignes d'une ListeBox, je génère sur le formulaire une TextBox.
Cela fonctionne bien.

Par contre, la position en hauteur TOP est identique à la valeur de l'index du select de la ligne de la listBox

Mon souhait est peu importe la position de la ligne sélectionnée dans la listbox Créera une TextBox sur la 1er ligne prévue à cette effet dans le formulaire
la seconde sélection créera le TextBox en dessous de la 1er TextBox. etc...

Il semble que ce soit cette variable qui faut incrémenter différemment --> .Top = 130 + (j) * 15 --> mais diférents test ne donnent rien

voici le code pour plus de clarté

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
 
 
Private Sub ListBox_ARO_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
 
Dim i As Integer
Dim J as integer
Dim ctrl As Control
 
    For i = 0 To ListBox_ARO.ListCount - 1
j = 1
        If ListBox_ARO.Selected(i) Then
j = j + 1
            'Label Nom Arôme
            Set ctrl = Me.Controls.Add("Forms.Label.1")
            With ctrl
                .Height = 12
                .Width = 234
                .Left = 24
                .Top = 130 + (j) * 15
                .Caption = Select_Nom_Arome & ListBox_ARO.List(i, 2)
                .Name = "Lab_" & Select_Nom_Arome & ListBox_ARO.List(i, 2)
                .TabIndex = i
                .Font.Name = "Verdana"
                .Font.size = 10
            End With
 
            ' TextBox Dosage Arôme
            Set ctrl = Me.Controls.Add("Forms.TextBox.1")
            With ctrl
                .Height = 18
                .Width = 24
                .Left = 264
                .Top = 126 + (j) * 21
                .Name = "TB_" & Select_Nom_Arome & ListBox_ARO.List(i, 2)
                .TabIndex = i
                .Font.Name = "Verdana"
                .Font.size = 10
            End With
 
            'Label symbôle %
            Set ctrl = Me.Controls.Add("Forms.Label.1")
            With ctrl
                .Height = 12
                .Width = 12
                .Left = 289
                .Top = 130 + (j) * 15
                .Caption = "%"
                .TabIndex = i
                .Font.Name = "Verdana"
                .Font.size = 10
            End With
 
            ' TextBox Quantité dû au dosage Arôme
            Set ctrl = Me.Controls.Add("Forms.TextBox.1")
            With ctrl
                .Height = 18
                .Width = 30
                .Left = 310
                .Top = 126 + (j) * 21
                .Name = "TB_Q_" & Select_Nom_Arome & ListBox_ARO.List(i, 2)
                .TabIndex = i
                .Font.Name = "Verdana"
                .Font.size = 10
            End With
 
            'Label ml
            Set ctrl = Me.Controls.Add("Forms.Label.1")
            With ctrl
                .Height = 12
                .Width = 12
                .Left = 342
                .Top = 130 + (j) * 15
                .Caption = "ml"
                .TabIndex = i
                .Font.Name = "Verdana"
                .Font.size = 10
            End With
        End If
 
    Next i
 
    ' lecture du nom de control type TextBox & Label
    Dim Ob As Control
    For Each Ob In Me.Controls
 
        If TypeOf Ob Is MSForms.TextBox Then
           ' MsgBox Ob.Name
            Debug.Print Ob.Name
        End If
        If TypeOf Ob Is MSForms.label Then
           ' MsgBox Ob.Name
            Debug.Print Ob.Name
        End If
    Next
 
 
End Sub

(j'espère que l'explication n'est pas confuse)

une idée ? merci ...