Bonjour

Je suis désolé tout d'abord si un forum sur ce sujet existe déjà.

Je suis en train de coder un petit programme, qui dans un certain module, en cliquant sur un bouton "ajout", m'ajoute des lignes à partir d'une ligne initiale. Jusque là aucun soucis. Par contre, je souhaite que, sur cette ligne, suivant ce qui est choisi dans la première combobox, les items (collection) dans une seconde soit différents.

Je m'explique avec le code suivant :

ceci me permet de créer une ligne supplémentaire lors d'un click sur le bouton, puis une autre, tant que l'on appuie.

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
 
Private Sub Button8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
i = i + 1
j = 100 + i
k = 200 + i
l = 300 + i
m = 400 + i
 
Dim Richtextbox As System.Windows.Forms.RichTextBox
Dim Textbox(i) As System.Windows.Forms.TextBox
Dim Richtextbox1(k) As System.Windows.Forms.RichTextBox
Dim Combobox As System.Windows.Forms.ComboBox
Dim combobox1 As System.Windows.Forms.ComboBox
Dim combobox2(k) As System.Windows.Forms.ComboBox
Dim combobox3(l) As System.Windows.Forms.ComboBox
Dim combobox4(m) As System.Windows.Forms.ComboBox
Dim Familles() As String = {"", "toto", "tata", "titi"}
Dim Type_toto() As String = {"Type 1 = 20 h", "Type 2 = 40 h", "Type 3 = 80 h", "Type 4 = 160 h", "Type 5 = 240 h"}
Dim Type_tata() As String = {"Type 1 = 8 h", "Type 2 = 16 h", "Type 3 = 40 h", "Type 4 = 60 h", "Type 5 = 80 h"}
Dim Type_titi() As String = {"Type 1 = 4 h", "Type 2 = 8 h", "Type 3 = 16 h", "Type 4 = 40 h", "Type 5 = 60 h"}
 
Richtextbox = New System.Windows.Forms.RichTextBox
Textbox(i) = New System.Windows.Forms.TextBox
Richtextbox1(k) = New System.Windows.Forms.RichTextBox
Combobox = New System.Windows.Forms.ComboBox
combobox1 = New System.Windows.Forms.ComboBox
combobox2(k) = New System.Windows.Forms.ComboBox
combobox3(l) = New System.Windows.Forms.ComboBox
combobox4(m) = New System.Windows.Forms.ComboBox
 
b = SplitContainer1.Height
 
If i = 1 Then
 
Richtextbox.Name = ("Richtextbox" & i)
Richtextbox.Visible = True
Richtextbox.Top = RichTextBox0.Top + 40
Richtextbox.Left = RichTextBox0.Left
Richtextbox.Height = RichTextBox0.Height
Richtextbox.Width = RichTextBox0.Width
Richtextbox.TabIndex = 0
Richtextbox.Multiline = True
Richtextbox.SelectionFont = New Font("Arial", 9, FontStyle.Bold)
 
Combobox.Name = "Combobox" & i
Combobox.Visible = True
Combobox.Top = ComboBox0.Top + 40
Combobox.Left = ComboBox0.Left
Combobox.Height = ComboBox0.Height
Combobox.Width = ComboBox0.Width
Combobox.TabIndex = 0
Combobox.DropDownStyle = ComboBoxStyle.DropDownList
Combobox.DataSource = Familles
 
combobox1.Name = "Combobox" & (j)
combobox1.Visible = True
combobox1.Top = ComboBox100.Top + 40
combobox1.Left = ComboBox100.Left
combobox1.Height = ComboBox100.Height
combobox1.Width = ComboBox100.Width
combobox1.TabIndex = 0
combobox1.DropDownStyle = ComboBoxStyle.DropDownList
 
combobox2(k).Visible = True
combobox2(k).Top = ComboBox200.Top + 40
combobox2(k).Left = ComboBox200.Left
combobox2(k).Name = "Combobox" & (k)
combobox2(k).Height = ComboBox200.Height
combobox2(k).Width = ComboBox200.Width
combobox2(k).TabIndex = 0
combobox2(k).DropDownStyle = ComboBoxStyle.DropDownList
 
combobox3(l).Visible = True
combobox3(l).Top = ComboBox300.Top + 40
combobox3(l).Left = ComboBox300.Left
combobox3(l).Name = "Combobox" & (l)
combobox3(l).Height = ComboBox300.Height
combobox3(l).Width = ComboBox300.Width
combobox3(l).TabIndex = 0
combobox3(l).DropDownStyle = ComboBoxStyle.DropDownList
 
combobox4(m).Visible = True
combobox4(m).Top = ComboBox400.Top + 40
combobox4(m).Left = ComboBox400.Left
combobox4(m).Name = "Combobox" & (m)
combobox4(m).Height = ComboBox400.Height
combobox4(m).Width = ComboBox400.Width
combobox4(m).TabIndex = 0
combobox4(m).DropDownStyle = ComboBoxStyle.DropDownList
 
Richtextbox1(k).Visible = True
Richtextbox1(k).Top = RichTextBox200.Top + 40
Richtextbox1(k).Left = RichTextBox200.Left
Richtextbox1(k).Name = "Richtextbox" & i
Richtextbox1(k).Height = RichTextBox200.Height
Richtextbox1(k).Width = RichTextBox200.Width
Richtextbox1(k).TabIndex = 0
 
Textbox(i).Visible = True
Textbox(i).Top = TextBox0.Top + 40
Textbox(i).Left = TextBox0.Left
Textbox(i).Name = "textbox" & i
Textbox(i).Height = TextBox0.Height
Textbox(i).Width = TextBox0.Width
Textbox(i).TabIndex = 0
Textbox(i).BackColor = Color.WhiteSmoke
Textbox(i).ReadOnly = True
 
'Richtextbox(i).Text = "Commentaires..."
'Richtextbox(i).ForeColor = Color.DarkGray
 
SplitContainer1.Panel1.Controls.Add(Richtextbox)
 
SplitContainer2.Panel1.Controls.Add(Combobox)
SplitContainer3.Panel1.Controls.Add(combobox1)
SplitContainer4.Panel1.Controls.Add(combobox2(k))
SplitContainer4.Panel2.Controls.Add(combobox3(l))
SplitContainer5.Panel1.Controls.Add(combobox4(m))
SplitContainer5.Panel2.Controls.Add(Richtextbox1(k))
SplitContainer5.Panel2.Controls.Add(Textbox(i))
a = Richtextbox.Top
 
Else
Richtextbox.Visible = True
Richtextbox.Top = a + 40
Richtextbox.Left = RichTextBox0.Left
Richtextbox.Name = "Richtextbox" & i
Richtextbox.Height = RichTextBox0.Height
Richtextbox.Width = RichTextBox0.Width
Richtextbox.TabIndex = 0
Richtextbox.SelectionFont = New Font("Arial", 9, FontStyle.Bold)
 
Combobox.Visible = True
Combobox.Top = a + 40
Combobox.Left = ComboBox0.Left
Combobox.Name = "combobox" & i
Combobox.Height = ComboBox0.Height
Combobox.Width = ComboBox0.Width
Combobox.TabIndex = 0
Combobox.DropDownStyle = ComboBoxStyle.DropDownList
Combobox.DataSource = Familles
 
combobox1.Visible = True
combobox1.Top = a + 40
combobox1.Left = ComboBox100.Left
combobox1.Name = "combobox" & (j)
combobox1.Height = ComboBox100.Height
combobox1.Width = ComboBox100.Width
combobox1.TabIndex = 0
combobox1.DropDownStyle = ComboBoxStyle.DropDownList
 
combobox2(k).Visible = True
combobox2(k).Top = a + 40
combobox2(k).Left = ComboBox200.Left
combobox2(k).Name = "combobox" & (k)
combobox2(k).Height = ComboBox200.Height
combobox2(k).Width = ComboBox200.Width
combobox2(k).TabIndex = 0
combobox2(k).DropDownStyle = ComboBoxStyle.DropDownList
 
combobox3(l).Visible = True
combobox3(l).Top = a + 40
combobox3(l).Left = ComboBox300.Left
combobox3(l).Name = "combobox" & (l)
combobox3(l).Height = ComboBox300.Height
combobox3(l).Width = ComboBox300.Width
combobox3(l).TabIndex = 0
combobox3(l).DropDownStyle = ComboBoxStyle.DropDownList
 
combobox4(m).Visible = True
combobox4(m).Top = a + 40
combobox4(m).Left = ComboBox400.Left
combobox4(m).Name = "combobox" & (m)
combobox4(m).Height = ComboBox400.Height
combobox4(m).Width = ComboBox400.Width
combobox4(m).TabIndex = 0
combobox4(m).DropDownStyle = ComboBoxStyle.DropDownList
 
Richtextbox1(k).Visible = True
Richtextbox1(k).Top = a + 40
Richtextbox1(k).Left = RichTextBox200.Left
Richtextbox1(k).Name = "Richtextbox" & i
Richtextbox1(k).Height = RichTextBox200.Height
Richtextbox1(k).Width = RichTextBox200.Width
Richtextbox1(k).TabIndex = 0
 
Textbox(i).Visible = True
Textbox(i).Top = a + 40
Textbox(i).Left = TextBox0.Left
Textbox(i).Name = "textbox" & i
Textbox(i).Height = TextBox0.Height
Textbox(i).Width = TextBox0.Width
Textbox(i).TabIndex = 0
Textbox(i).BackColor = Color.WhiteSmoke
Textbox(i).ReadOnly = True
 
SplitContainer1.Height = b + 40
SplitContainer5.Height = b + 40
SplitContainer2.Height = b + 40
SplitContainer3.Height = b + 40
SplitContainer1.Panel1.Controls.Add(Richtextbox)
SplitContainer2.Panel1.Controls.Add(Combobox)
SplitContainer3.Panel1.Controls.Add(combobox1)
SplitContainer4.Panel1.Controls.Add(combobox2(k))
SplitContainer4.Panel2.Controls.Add(combobox3(l))
SplitContainer5.Panel1.Controls.Add(combobox4(m))
SplitContainer5.Panel2.Controls.Add(Richtextbox1(k))
SplitContainer5.Panel2.Controls.Add(Textbox(i))
a = Richtextbox.Top
b = SplitContainer1.Height
End If
 
End Sub
jusque là ca marche.

par contre dès que je sélectionne par exemple toto dans la Combobox1 (= (Combobox & i) avec i = 1), combobox créer par un premier click sur "ajout", il faudrait que la combobox100 (= (Combobox & j) avec j = 100) soit le type_toto.

Or j'arrive à faire ceci pour la première ligne (ligne toujours présente) avec la commande :

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
 
Public Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox0.SelectedIndexChanged
Dim Type_toto() As String = {"Type 1 = 20 h", "Type 2 = 40 h", "Type 3 = 80 h", "Type 4 = 160 h", "Type 5 = 240 h"}
Dim Type_tata() As String = {"Type 1 = 8 h", "Type 2 = 16 h", "Type 3 = 40 h", "Type 4 = 60 h", "Type 5 = 80 h"}
Dim Type_titi() As String = {"Type 1 = 4 h", "Type 2 = 8 h", "Type 3 = 16 h", "Type 4 = 40 h", "Type 5 = 60 h"}
If ComboBox0.Text = "toto" Then
ComboBox100.Refresh()
ComboBox100.DataSource = Type_toto
ElseIf ComboBox0.Text = "tata" Then
ComboBox100.Refresh()
ComboBox100.DataSource = Type_tata
ElseIf ComboBox0.Text = "titi" Then
ComboBox100.Refresh()
ComboBox100.DataSource = Type_titi
End If
End Sub
Par contre pour toutes les autres combobox générées automatiquement, je n'arrive pas à écrire le même type d'action "général".

du genre

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
 
Public Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ("ComboBox" & i).SelectedIndexChanged
Dim Type_toto() As String = {"Type 1 = 20 h", "Type 2 = 40 h", "Type 3 = 80 h", "Type 4 = 160 h", "Type 5 = 240 h"}
Dim Type_tata() As String = {"Type 1 = 8 h", "Type 2 = 16 h", "Type 3 = 40 h", "Type 4 = 60 h", "Type 5 = 80 h"}
Dim Type_titi() As String = {"Type 1 = 4 h", "Type 2 = 8 h", "Type 3 = 16 h", "Type 4 = 40 h", "Type 5 = 60 h"}
If ("ComboBox" & i).Text = "toto" Then
("ComboBox" & j).Refresh()
("ComboBox" & j).DataSource = Type_toto
ElseIf ("ComboBox" & i).Text = "tata" Then
("ComboBox" & j).Refresh()
("ComboBox" & j).DataSource = Type_tata
ElseIf ("ComboBox" & i).Text = "titi" Then
("ComboBox" & j).Refresh()
("ComboBox" & j).DataSource = Type_titi
End If
End Sub
Quelqu'un pourrait il m'aider ?

J'espère avoir été assez clair.

Merci énormément du temps que vous passerez à me répondre.

A+

Neolive