C
C#6mo ago
Neoon

I am trying to display the data from one form to another and it’s not working

So my problem is . I have 3 forms one interface that one is fine second form 2 admin only rights to access and manipulate the way they want to create a quiz . Made my a question and 4 answers and finally my 3 form this is where the problem is I am trying to display whatever is written on form 2 to show on my form 3 but I can’t it keeps saying my index is out of range Help please!!
No description
4 Replies
Neoon
Neoon6mo ago
Form 2 design Form 3
Neoon
Neoon6mo ago
No description
Anu6is
Anu6is6mo ago
You'd need to show some actual code, not the form design.
Neoon
Neoon6mo ago
Trueeeee Wait I kinda fix it but if you have any suggestions to insure my code it’s better practice I am all ears 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];
Want results from more Discord servers?
Add your server
More Posts