Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is in the QuestionDisplay class.
- //MCQ
- public void AddOption_mcq(string optionText, bool arg, int QNo, int option)
- {
- CustomRadio rb = new CustomRadio();
- rb.Text = optionText;
- rb.Location = new Point(3, 40 + grbOptions.Controls.Count * 30);
- rb.AutoSize = true;
- rb.Checked = arg;
- rb.QuestionNumber = QNo;
- rb.optionId = option;
- rb.CheckedChanged += delegate(Object sender, System.EventArgs e)
- {
- temp = sender as CustomRadio;
- if (!ResponseMCQ.ContainsKey(QNo)) //First time question is marked, ResponseMCQ is a <int,ButtonBase> dict.
- {
- ResponseMCQ.Add(QNo, temp);
- }
- else
- ResponseMCQ[QNo] = temp; //All other times
- };
- grbOptions.Controls.Add(rb); //grbOptions is a groupbox control.
- }
- //MSQ
- public void AddOption_msq(string optionText, bool arg, int QNo, int option)
- {
- CustomChecks cb = new CustomChecks();
- cb.Text = optionText;
- cb.Location = new Point(3, 40 + grbOptions.Controls.Count * 30);
- cb.AutoSize = true;
- cb.Checked = arg;
- cb.QuestionNumber = QNo;
- cb.optionId = option;
- cb.CheckedChanged += delegate(Object sender, System.EventArgs e)
- {
- temp = sender as CustomChecks;
- if(MSQs.Any())
- foreach (CustomChecks C in MSQs) //Clear elements from List if on a different question
- {
- if (C.QuestionNumber != ((CustomChecks)temp).QuestionNumber)
- {
- IsDifferent = true;
- break;
- }
- }
- if (IsDifferent == true)
- {
- MSQs.Clear();
- IsDifferent = false;
- }
- if(!MSQs.Any(x => x.Text.Equals(optionText))) //Check if the checkbox already exists in the List
- MSQs.Add(temp);
- if (!ResponseMSQ.ContainsKey(QNo)) //First time the question is marked
- {
- ResponseMSQ.Add(QNo, MSQs);
- }
- else
- ResponseMSQ[QNo] = MSQs; //All other times
- };
- grbOptions.Controls.Add(cb);
- if (MSQs.Any())
- {
- foreach (CustomChecks C in MSQs)
- {
- foreach (CustomChecks D in grbOptions.Controls)
- {
- if (D.Text.Equals(C.Text))
- {
- D.Checked = C.Checked;
- }
- }
- }
- }
- }
- //In the main project, this is how I collect MCQ responses -:
- temp = questionDisplay1.GetResponse; //questionDisplay1 is a QuestionDisplay object and GetResponse is a ButtonBase object, used to temporarily store the clicked radio button(CustomRadio object).
- //MCQResponse is a Dictionary<int, ButtonBase> which stores <QuestionNumber, CustomRadio>.
- if (QuesTypes[i].Equals("MCQ"))
- {
- if (questionDisplay1.MCQResponse.TryGetValue(i, out temp) && questionDisplay1.MCQResponse[i].Text.Equals(s))
- {
- questionDisplay1.AddOption_mcq(s, true, i, optionId);
- }
- else
- questionDisplay1.AddOption_mcq(s, false, i, optionId);
- }
Advertisement
Add Comment
Please, Sign In to add comment