// Used to change to another display that is stored by this component public void ChangeDisplay(string newDisplayID) { NextQuestionBox.Visible = true; // Show the "Next" boxes at the bottom of the table NextCorrectAnswerBox.Visible = true; NextWrongAnswer1Box.Visible = true; NextWrongAnswer2Box.Visible = true; StoreDisplay(); // Store this display in preparation for switching if (storedDetails.ContainsKey(username) && storedDetails[username].ContainsKey(newDisplayID)) // If this display already exists { questions = new List<TextBox>(storedDetails[username][newDisplayID].questions); // Show all details from the found display correctAnswers = new List<TextBox>(storedDetails[username][newDisplayID].correctAnswers); wrongAnswers1 = new List<TextBox>(storedDetails[username][newDisplayID].wrongAnswers1); wrongAnswers2 = new List<TextBox>(storedDetails[username][newDisplayID].wrongAnswers2); UpdateDisplay(); } else // If the display does not already exist { questions = new List<TextBox>(); // Clear all columns correctAnswers = new List<TextBox>(); wrongAnswers1 = new List<TextBox>(); wrongAnswers2 = new List<TextBox>(); UserDatabase userDB = new UserDatabase(); // Initialise a new UserDatabase for reading purposes UserQuestions userQuestions = userDB.getUserQuestions(username); // Read the current user's questions List<string[]> details = userQuestions.getQuestions(newDisplayID); // Extract the questions for this set for (int i = 0; i < details.Count; i++) // for each question { questions.Add(new TextBox()); // Add a new cell for the question questions[i].BorderStyle = BorderStyle.FixedSingle; // Update the border questions[i].Click += new EventHandler(BoxClicked); // Add an event handler so that when the cell is clicked the Enter Value panel appears questions[i].Text = details[i][0]; // Fill the cell with the question correctAnswers.Add(new TextBox()); // Add a new cell for the Correct Answer correctAnswers[i].BorderStyle = BorderStyle.FixedSingle; correctAnswers[i].Click += new EventHandler(BoxClicked); correctAnswers[i].Text = details[i][1]; wrongAnswers1.Add(new TextBox()); // Add a new cell for the wrong answer 1 wrongAnswers1[i].BorderStyle = BorderStyle.FixedSingle; wrongAnswers1[i].Click += new EventHandler(BoxClicked); wrongAnswers1[i].Text = details[i][2]; wrongAnswers2.Add(new TextBox()); // Add a new cell for the wrong answer 2 wrongAnswers2[i].BorderStyle = BorderStyle.FixedSingle; wrongAnswers2[i].Click += new EventHandler(BoxClicked); wrongAnswers2[i].Text = details[i][3]; } UpdateDisplay(); // Update the display to show the columns to the user } currentID = newDisplayID; // Update the currentID tracking variable to track the current ID }