private void BtnDelete_Click(object sender, RoutedEventArgs e) { try { //Check if the cboBox is not selecting anything if (cboQorAs.SelectedItem == null) { throw new Exception("You must select a(n) " + qaMode.ToString() + " to delete"); } else { if (qaMode == QAMode.Answer) { //Delete the Answer Answer answer = new Answer(); answer = answers.ElementAt(cboQorAs.SelectedIndex); int result = answer.Delete(); if (result > 0) { lblStatus.Content = "Removed Answer: " + answer.Text; } else { throw new Exception("Answer not deleted"); } //Remove from the answer list answers.Remove(answer); //Rebind the combobox rebindComboBox(qaMode); } else { //Delete the Question Question question = new Question(); question = questions.ElementAt(cboQorAs.SelectedIndex); int result = question.DeleteQuestion(); if (result > 0) { lblStatus.Content = "Removed Question: " + question.Text; } else { throw new Exception("Question not deleted"); } //Remove from the answer list questions.Remove(question); //Rebind the combobox rebindComboBox(qaMode); } } } catch (Exception ex) { lblStatus.Content = ex.Message; } }