Bonjour,

Débutant dans la programmation, je souhaite afficher mes données dans un DataGrid suivant le Modèle MVC. Seulement mes données n'apparaissent pas dans le DataGrid. Ne comprenant pas tous à fait le passage de Données avec le Binding, je pense que le problème vient de là car tous mon code semble "correcte" pour moi, je n'ai pas d'erreurs et j'ai regarder un peu partout sur le web pour comprendre comment lié mon DataGrid à ma source de donnée mais impossible :s.

Merci d'avance

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
 
private void Button_Click(object sender, RoutedEventArgs e)
       {
 
 
           test = new Collection<Habilitation>();
 
           HabilitationDao listeHabilitationCuid = new HabilitationDao();
           test = listeHabilitationCuid.rechercheHabilitation(cuid);
 
           this.DataContext = test;
 
       }//fin méthode
XAML
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
<DataGrid ItemsSource="{Binding ElementName=test}" Margin="40" FontSize="15" Grid.Column="2" Grid.RowSpan="2" AlternatingRowBackground="LightBlue">
                   <DataGrid.Columns>
                       <DataGridTextColumn Binding="{Binding code}" x:Name="dataGrid_codehabilitation" Header="Code Habilitation" />
                       <DataGridTextColumn Binding="{Binding nom}" x:Name="dataGrid_nom" Header="Nom"  />
                       <DataGridTextColumn Binding="{Binding prenom}" x:Name="dataGrid_prenom" Header="Prénom"  />
                       <DataGridTextColumn Binding="{Binding applicationLibelle}" x:Name="dataGrid_application" Header="Application" />
                       <DataGridTextColumn Binding="{Binding perimetreLibelle}" x:Name="dataGrid_perimetre" Header="Périmètre" />
                       <DataGridTextColumn Binding="{Binding dateHabilitation}" x:Name="dataGrid_dateHabilitation" Header="Date d'Habilitation" />
                       <DataGridTextColumn Binding="{Binding habiliteur}" x:Name="dataGrid_habiliteur" Header="Habiliteur" />
                   </DataGrid.Columns>
               </DataGrid>
Class HabilitationDao

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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
 
//Liste des habilitations pour un CUID
       public Collection<Habilitation> rechercheHabilitation(string cuid)
       {
           Collection<Habilitation> listHabilitation = new Collection<Habilitation>();
           BDDHelper db = new BDDHelper();
 
           Habilitation h = null;
           try
           {
               string query;
               MySqlConnection cnx = db.open();
               query = "SELECT ag2_ha_code, ";
               query += "ag2_ha_Identifiant, ";
               query += "ag2_ha_Nom, ";
               query += "ag2_ha_Prenom, ";
               query += "ag2_ha_MotDePasse, ";
               query += "ag2_ha_Application, ";
               query += "ag2_ha_ApplicationLibelle, ";
               query += "ag2_ha_Profil, ";
               query += "ag2_ha_Organisation, ";
               query += "ag2_ha_Perimetre, ";
               query += "ag2_ha_PerimetreLibelle, ";
               query += "ag2_ha_Entite, ";
               query += "ag2_ha_EntiteLibelle, ";
               query += "ag2_ha_DateHabilitation, ";
               query += "ag2_ha_Habiliteur, ";
               query += "ag2_ha_DateSuppression, ";
               query += "ag2_ha_Resilieur, ";
               query += "ag2_ha_DerniereHabilitation, ";
               query += "ag2_ha_OrganisationO, ";
               query += "ag2_ha_ImpressionLogo ";
               query += "FROM ag2_habilitations ";
               query += "WHERE ag2_ha_Identifiant = '";
               query += cuid;
               query += "';";
 
 
               MySqlCommand cmd = new MySqlCommand(query, cnx);
               MySqlDataReader dr = cmd.ExecuteReader();
 
               while (dr.Read())
               {
                   //CODE
                   string code = dr.GetString("ag2_ha_code");
                   //CUID ORANGE
                   string cuidOrange;
                   if (!dr.IsDBNull(1))
                   {
                       cuidOrange = dr.GetString("ag2_ha_Identifiant");
                   }
                   else
                   {
                       cuidOrange = Convert.ToString(null);
                   }
                   //NOM
                   string nom;
                   if (!dr.IsDBNull(2))
                   {
                       nom = dr.GetString("ag2_ha_Nom");
                   }
                   else
                   {
                       nom = Convert.ToString(null);
                   }
                   //PRENOM
                   string prenom;
                   if (!dr.IsDBNull(3))
                   {
                       prenom = dr.GetString("ag2_ha_Prenom");
                   }
                   else
                   {
                       prenom = Convert.ToString(null);
                   }
                   //PASSWORD
                   string password;
                   if (!dr.IsDBNull(4))
                   {
                       password = dr.GetString("ag2_ha_MotDePasse");
                   }
                   else
                   {
                       password = Convert.ToString(null);
                   }
                   //APPLICATION
                   string application;
                   if (!dr.IsDBNull(5))
                   {
                       application = dr.GetString("ag2_ha_Application");
                   }
                   else
                   {
                       application = Convert.ToString(null);
                   }
                   //APLICATION LIBELLE
                   string applicationLibelle;
                   if (!dr.IsDBNull(6))
                   {
                       applicationLibelle = dr.GetString("ag2_ha_ApplicationLibelle");
                   }
                   else
                   {
                       applicationLibelle = Convert.ToString(null);
                   }
                   //PROFIL
                   string profil;
                   if (!dr.IsDBNull(7))
                   {
                       profil = dr.GetString("ag2_ha_Profil");
                   }
                   else
                   {
                       profil = Convert.ToString(null);
                   }
                   //ORGANISATION
                   string organisation;
                   if (!dr.IsDBNull(8))
                   {
                       organisation = dr.GetString("ag2_ha_Organisation");
                   }
                   else
                   {
                       organisation = Convert.ToString(null);
                   }
                   //PERIMETRE
                   string perimetre;
                   if (!dr.IsDBNull(9))
                   {
                       perimetre = dr.GetString("ag2_ha_Perimetre");
                   }
                   else
                   {
                       perimetre = Convert.ToString(null);
                   }
                   //PERIMETRE LIBELLE
                   string perimetreLibelle;
                   if (!dr.IsDBNull(10))
                   {
                       perimetreLibelle = dr.GetString("ag2_ha_PerimetreLibelle");
                   }
                   else
                   {
                       perimetreLibelle = Convert.ToString(null);
                   }
                   //ENTITE
                   string entite;
                   if (!dr.IsDBNull(11))
                   {
                       entite = dr.GetString("ag2_ha_Entite");
                   }
                   else
                   {
                       entite = Convert.ToString(null);
                   }
                   //ENTITE LIBELLE
                   string entiteLibelle;
                   if (!dr.IsDBNull(12))
                   {
                       entiteLibelle = dr.GetString("ag2_ha_EntiteLibelle");
                   }
                   else
                   {
                       entiteLibelle = Convert.ToString(null);
                   }
                   //DATE HABILITATION
                   DateTime dateHabilitation;
                   if (!dr.IsDBNull(13))
                   {
                       dateHabilitation = dr.GetDateTime("ag2_ha_DateHabilitation");
                   }
                   else
                   {
                       dateHabilitation = Convert.ToDateTime(null);
                   }
                   //HABILITEUR
                   string habiliteur;
                   if (!dr.IsDBNull(14))
                   {
                       habiliteur = dr.GetString("ag2_ha_Habiliteur");
                   }
                   else
                   {
                       habiliteur = Convert.ToString(null);
                   }
                   //DATE SUPRESSION
                   DateTime dateSupression;
                   if (!dr.IsDBNull(15))
                   {
                       dateSupression = dr.GetDateTime("ag2_ha_DateSuppression");
                   }
                   else
                   {
                       dateSupression = Convert.ToDateTime(null);
                   }
                   //RESILIEUR
                   string resilieur;
                   if (!dr.IsDBNull(16))
                   {
                       resilieur = dr.GetString("ag2_ha_Resilieur");
                   }
                   else
                   {
                       resilieur = Convert.ToString(null);
                   }
                   //DERNIERE HABILITATION
                   DateTime derniereHabilitation;
                   if (!dr.IsDBNull(17))
                   {
                       derniereHabilitation = dr.GetDateTime("ag2_ha_DerniereHabilitation");
                   }
                   else
                   {
                       derniereHabilitation = Convert.ToDateTime(null);
                   }
                   //ORGANISATION OLD
                   string organisationOld;
                   if (!dr.IsDBNull(18))
                   {
                       organisationOld = dr.GetString("ag2_ha_OrganisationO");
                   }
                   else
                   {
                       organisationOld = Convert.ToString(null);
                   }
 
                   //Appel constructeur Habilitation
                   h = new Habilitation(code, cuidOrange, nom, prenom, password, application, applicationLibelle, profil, organisation, perimetre, perimetreLibelle, entite, entiteLibelle, dateHabilitation, habiliteur, dateSupression, resilieur, derniereHabilitation, organisationOld);
 
                   listHabilitation.Add(h);
 
               }
 
           }
           catch (MySqlException ex)
           {
               System.Console.WriteLine(ex.Message);
               MessageBox.Show(ex.Message);
           }
           finally
           {
               db.close();
           }
           return listHabilitation;
       }//fin méthode