Ejemplo n.º 1
0
        private void QuestionSelected(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                //Question was picked, find its answers
                Question question = new Question();

                if (cboQuestion.SelectedItem != null)
                {
                    question = questions.ElementAt(cboQuestion.SelectedIndex);

                    //Clear out all selections
                    cboCorrectAnswer.SelectedItem = null;
                    cboWrongAnswer1.SelectedItem  = null;
                    cboWrongAnswer2.SelectedItem  = null;
                    cboWrongAnswer3.SelectedItem  = null;

                    int wrongAnswersInserted = 0;

                    //Loop through each answer and select it in a combo box
                    foreach (Answer a in question.Answers)
                    {
                        if (a.IsCorrect)
                        {
                            cboCorrectAnswer.SelectedIndex = answers.FindIndex(ans => ans.Id == a.Id);
                        }
                        else
                        {
                            switch (wrongAnswersInserted)
                            {
                            case 0:
                                cboWrongAnswer1.SelectedIndex = answers.FindIndex(ans => ans.Id == a.Id);
                                break;

                            case 1:
                                cboWrongAnswer2.SelectedIndex = answers.FindIndex(ans => ans.Id == a.Id);
                                break;

                            case 2:
                                cboWrongAnswer3.SelectedIndex = answers.FindIndex(ans => ans.Id == a.Id);
                                break;

                            default:
                                break;
                            }

                            wrongAnswersInserted++;
                        }
                    }
                }

                //Clear out status label
                lblStatus.Content = String.Empty;
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }