Bonjour à tous,
Je me retrouve face à un petit problème pour compléter des ComboBox en fonction du choix selectionné dans la ComboBox principale. En récupérant les données dans des dictionnary.
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 ' ComboBoxData.vb Public Class ComboBoxData ' Listing des types de raccordements Public Dic_typeRacco As New Dictionary(Of Integer, String) From { {0, "Aero Souterrain"}, {1, "Branchement Souterrain"}, {2, "Branchement Immeuble"}, {3, "Colonne Montante"}, {4, "Immeuble de 5 étages <= 44Log"}, {5, "Immeuble de 7 étages <= 44Log"}, {6, "Ft pour remplacement d'un CPE"} } ' Liste des prestations pour l'aero souterrain Public Dic_typePrestatsAeroSout As New Dictionary(Of Integer, String) From { {1, "Raccordement unitaire"}, {2, "2 ≤ nb raccordements ≤ 10"}, {3, "10 ≤ nb raccordements ≤ 25"}, {4, "25 < nb raccordements ≤ 50"}, {5, "50 < nb raccordements ≤ 100"}, {6, "100 < nb raccordements ≤ 250"}, {7, "250 < nb raccordements ≤ 500"}, {8, "Nb raccordements > 500"} } ' Prestations pour un branchement Souterrain Public Dic_typePrestatsSout As New Dictionary(Of Integer, String) From { {1, "Raccordement unitaire"}, {2, "2 ≤ nb raccordements ≤ 10"}, {3, "10 ≤ nb raccordements ≤ 25"}, {4, "25 < nb raccordements ≤ 50"}, {5, "50 < nb raccordements ≤ 100"}, {6, "100 < nb raccordements ≤ 250"}, {7, "250 < nb raccordements ≤ 500"}, {8, "Nb raccordements > 500"} } ' etc... End Class
Voilà ce code fonctionne plus ou moins certes, mais je préférerais éviter la partie découpage, je suis sûr qu'il y a beaucoup plus simple mais je n'ai pas réussi.
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 ' IHM.vb Public Class IHM Dim cbData As New ComboBoxData Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Listing des types de raccordements infoRacc_typeRacc.DataSource = New BindingSource(cbData.Dic_typeRacco, Nothing) infoRacc_typeRacc.DisplayMember = "Value" infoRacc_typeRacc.ValueMember = "Key" Dim selectedItem As String selectedItem = infoRacc_typeRacc.SelectedItem.ToString() selectedItem = selectedItem.Substring(4, selectedItem.Length - 5) ' ComboBox n°2 affiche les prestats aero si ComboBox n°1 = aero ' Prestations pour un branchement Aero Souterrain If selectedItem = cbData.Dic_typeRacco.Item("0") Then infoRacc_prestation.DataSource = New BindingSource(cbData.Dic_typePrestatsAeroSout, Nothing) infoRacc_typeRacc.DisplayMember = "Value" infoRacc_typeRacc.ValueMember = "Key" End If ' Même principe, cb2 = prestas sout si cb1 = sout ' Prestations pour un branchement Souterrain If selectedItem = cbData.Dic_typeRacco.Item("1") Then infoRacc_prestation.DataSource = New BindingSource(cbData.Dic_typePrestatsSout, Nothing) infoRacc_typeRacc.DisplayMember = "Value" infoRacc_typeRacc.ValueMember = "Key" End If End Sub ' etc... Private Sub infoRacc_prestation_SelectedIndexChanged_1(sender As System.Object, e As System.EventArgs) Handles infoRacc_prestation.SelectedIndexChanged infoRacc_prestation.Items.Clear() End Sub End Class
Second problème, je n'arrive pas à actualiser ma ComboBox n°2 si je change la valeur choisis par la ComboBox n°1.
Merci d'avance pour le coup de pouce![]()
Partager