private void AddButton_Click(object sender, EventArgs e) { //When the add button is pressed the question must be coppied from the stored questions, to the NewQuiz collection if (QuestionListBox.SelectedItem == null) { return; } else if (NewQuiz.Count() == 15) { //Only 15 questions MAX are allowed per quiz so if they try to add too many the program will display this error MessageBox.Show("Error, Invalid number of items, please select between 3 and 15 questions. Remove items or create multiple quizzes.", "Error", MessageBoxButtons.OK); return; } StoredQuestions SelectedQuestion = (StoredQuestions)QuestionListBox.SelectedItem; //If the quiz already contains the question then this message will display if (NewQuiz.Contains(SelectedQuestion)) { string message = "This question has already been added to the quiz!"; string caption = "Error Detected in Input"; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show(message, caption, buttons); return; } //If none of the other criteria have occured it will add the question to the quiz NewQuiz.Add(SelectedQuestion); //Resets the variables QuizListBox.DataSource = null; QuizListBox.DataSource = NewQuiz; QuizListBox.DisplayMember = "Question"; QuestionCapacityProgressBar.Increment(1); }
private void RemoveButton_Click(object sender, EventArgs e) { //If no question is selected then the question cannot be removed if (QuizListBox.SelectedItem == null) { return; } //The selected question is saved to a variable StoredQuestions SelectedQuestion = (StoredQuestions)QuizListBox.SelectedItem; //Removes the question from the quiz NewQuiz.Remove(SelectedQuestion); QuizListBox.DataSource = null; QuizListBox.DataSource = NewQuiz; QuizListBox.DisplayMember = "Question"; QuestionCapacityProgressBar.Increment(-1); }