Bonjour à tous,

Dans le cadre de mon stage, je réalise une petite application en C# sur Visual Studio.

Et bien sur, comme toujours, je rencontre une difficulté ^^...

J'essaye de faire une Classe ComboBox personnalisée( une liste déroulante donc) qui comprends deux Controls ( La comboBox et un TextBox).


Le problème est le suivant : Quand j'instancie ma classe, deux comboBox se créent l'une sur l'autre... L'un avec mes paramètres et l'autre vierge...

D'ou vient cette mystérieuse deuxième comboBox?



Voici mon Code :

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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Xml;
 
namespace Pepin
{
    public class comboPerso :ComboBox
    {
        ComboBox combo_medicament;
        TextBox box_quantite;
        XmlNode noeudMedic;
        string[] tab_medicament;
        string[] tab_apport;
 
 
            public comboPerso()
            {
                combo_medicament = new ComboBox();
                combo_medicament.Width=100;
                this.Controls.Add(combo_medicament);
 
 
                box_quantite = new TextBox();
                box_quantite.Location= new System.Drawing.Point (120,0);
                this.Controls.Add(box_quantite);
 
            }
 
            public void remplissageMedic()
            {
                combo_medicament.DropDownHeight = 400;
                XmlTextReader xmlMedicreader = new XmlTextReader("..\\..\\medicament.xml");
                XmlDocument xmlMedic = new XmlDocument();
                xmlMedic.Load(xmlMedicreader);
 
 
                noeudMedic = xmlMedic.DocumentElement;
                tab_medicament = new string[noeudMedic.ChildNodes.Count];
                tab_apport = new string[noeudMedic.ChildNodes.Count];
 
 
                for (int u = 0; u <= noeudMedic.ChildNodes.Count - 1; u++)
                {
                    XmlNode noeud = noeudMedic.ChildNodes[u];
                    tab_medicament[u]=noeud.ChildNodes[0].InnerText;
                    tab_apport[u]=noeud.ChildNodes[1].InnerText;
                    combo_medicament.Items.Add(tab_medicament[u]);
 
                }
            }
 
            public void remplissageDrogue()
            {
                combo_medicament.DropDownHeight = 400;
                XmlTextReader xmlMedicreader = new XmlTextReader("..\\..\\drogue.xml");
                XmlDocument xmlMedic = new XmlDocument();
                xmlMedic.Load(xmlMedicreader);
 
 
                noeudMedic = xmlMedic.DocumentElement;
                tab_medicament = new string[noeudMedic.ChildNodes.Count];
                tab_apport = new string[noeudMedic.ChildNodes.Count];
 
 
                for (int u = 0; u <= noeudMedic.ChildNodes.Count - 1; u++)
                {
                    XmlNode noeud = noeudMedic.ChildNodes[u];
                    tab_medicament[u] = noeud.ChildNodes[0].InnerText;
                    tab_apport[u] = noeud.ChildNodes[1].InnerText;
                    combo_medicament.Items.Add(tab_medicament[u]);
                }
            }
 
            public void remplissageAntibiotique()
            {
                combo_medicament.DropDownHeight = 400;
                XmlTextReader xmlMedicreader = new XmlTextReader("..\\..\\antibiotique.xml");
                XmlDocument xmlMedic = new XmlDocument();
                xmlMedic.Load(xmlMedicreader);
 
 
                noeudMedic = xmlMedic.DocumentElement;
                tab_medicament = new string[noeudMedic.ChildNodes.Count];
                tab_apport = new string[noeudMedic.ChildNodes.Count];
 
 
                for (int u = 0; u <= noeudMedic.ChildNodes.Count - 1; u++)
                {
                    XmlNode noeud = noeudMedic.ChildNodes[u];
                    tab_medicament[u] = noeud.ChildNodes[0].InnerText;
                    tab_apport[u] = noeud.ChildNodes[1].InnerText;
                    combo_medicament.Items.Add(tab_medicament[u]);
                }
            }
 
    }
}