bonjour,
voila j'ai fais un code qui affiche un label suivi de chekbox dynamiquement mais quand j'exécute je reçoit une exception:Ma question,c'est où exactement l'erreur et comment je peut la corrigéSystem.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet ligne 37.
Merçi d'avance.
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 Qcm test = new Qcm(); Question[] tab = new Question[test.get_nbQ()]; tab = test.get_Questions();//tableau de questions int p = 35; int Q = 0; try { for (int i = 1; i <= test.get_nbQ(); i++) { Q = p + 35; this.Controls.Add(new Label() { Name = "Q" + i, Location = new Point(57, Q), Size = new Size(1000, 30), Text = tab[i].get_libelle_Q() }); int j = 1; CheckBox[][] boxes = new CheckBox[tab[i].get_propDeQ().Count][]; p = Q + 28; foreach (string prop in tab[i].get_propDeQ())//get_propDeQ() //retourne une ArrayList de string { boxes[i][j] = new CheckBox();//ligne 37 boxes[i][j].Name = "prpQ" + i + j; boxes[i][j].Location = new Point(60, p); p += 28; boxes[i][j].Text = prop; boxes[i][j].Size = new Size(1000, 30); boxes[i][j].Checked = false; j++; } this.Controls.AddRange(boxes[i]); } } catch (Exception e) { MessageBox.Show(e.ToString(), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
Partager