Neoon
I am trying to display the data from one form to another and it’s not working
private void DisplayLoadedData()
{
{
// The labels in this case represent the questions.
Label[] dataLabels = new Label[4] { lbldata1, lbldata2, lbldata3, lbldata4 };
// The group boxes are the answers.
GroupBox[] dataGroupBoxes = new GroupBox[4] { grpdata1, grpdata2, grpdata3, grpdata4 };
// Loop through all loaded questions and display them in the labels
for (int i = 0; i < Math.Min(questions.Count, dataLabels.Length); i++)
{
// Display the current question in the label
dataLabels[i].Text = questions[i];
// Labels inside the group boxes
Label[] answerLabels = new Label[4]
{
dataGroupBoxes[i].Controls.Find($"lbldata{i + 1}A", true).FirstOrDefault() as Label,
dataGroupBoxes[i].Controls.Find($"lbldata{i + 1}B", true).FirstOrDefault() as Label,
dataGroupBoxes[i].Controls.Find($"lbldata{i + 1}C", true).FirstOrDefault() as Label,
dataGroupBoxes[i].Controls.Find($"lbldata{i + 1}D", true).FirstOrDefault() as Label
};
// Loop through the labels inside the group box
for (int j = 0; j < answerLabels.Length; j++)
{
// The label with the current answer
if (answerLabels[j] != null)
{
// Set the text of the label to the corresponding answer
answerLabels[j].Text = answers[i * 4 + j];
}
}
// Do not display radio buttons on Form 3
// Set the checked state of radio buttons based on the correct answer index from Form 2
int correctAnswerIndexForQuestion = correctAnswers[i];
9 replies