class Question { public string Libelle; public int Reponse; public List<string> Propositions; public Question(XPathNavigator aQuest) { Libelle = aQuest.SelectSingleNode("quest").Value; Reponse = aQuest.SelectSingleNode("rep").ValueAsInt; Propositions = new List<string>(); for (int i = 1; i < 6; i++) { string prop = aQuest.SelectSingleNode("prop" + i.ToString()).Value; if (prop != "") Propositions.Add(prop); } } }
List<Question> Questions;
private void button1_Click(object sender, EventArgs e) { XPathDocument doc = new XPathDocument(label1.Text + ".xml"); XPathNavigator nav = doc.CreateNavigator(); // On récupère un XPathNodeIterator sur les Record XPathNodeIterator iter = nav.Select("QCM/questions"); Questions = new List<Question>(); // Pour chaque Record try { button1.Enabled = false; while (iter.MoveNext()) { Questions.Add(new Question(iter.Current)); } } catch { } textBox1.Text = "Cliquez sur commencer pour voir les questions" + Environment.NewLine + "La durée de l'examen est : 30 minutes" + Environment.NewLine + "Le nombre de questions est :" + Questions.Count + Environment.NewLine; }
//itération: Question quest = Questions[i]; //ou boucle foreach(Question quest in Questions) ... for (i = 1; i < 6; i++) { if (quest.Propositions.Count<= i) //si il existe une i-ème proposition { //on rend le bouton visible ((RadioButton)(groupBox1.Controls.Find("radioButton" + i.ToString(), true)[0])).Visible=true; //et on affiche le texte de la proposition ((RadioButton)(groupBox1.Controls.Find("radioButton" + i.ToString(), true)[0])).Text = quest.Propositions[i]; } else //sinon { ((RadioButton)(groupBox1.Controls.Find("radioButton" + i.ToString(), true)[0])).Visible=false; } }
... //et on affiche le texte de la proposition ((RadioButton)(groupBox1.Controls.Find("radioButton" + i.ToString(), true)[0])).Text = quest.Propositions[i-1]; ...
string textreponse = quest.Propositions[quest.Reponse-1];
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question