I'm currently trying to create a nested loop system that prints out the colors from an imported csv file into multiple picture boxes. The first loop loads the picture boxes in the form into an array and the second one loops through the gameboard and the sets the color for each picture box from the csv file. I keep getting an error saying that "index is out of bounds of the array" in the array inside the second nested loop. How could I fix this? I'm using visual studio 2019 and the windows forms app (.net framework) template.
public partial class Form1 : Form
{
PictureBox[,] gameBoard = new PictureBox[7, 7];
private void Form1_Load(object sender, EventArgs e)
{
string[] startingconfigarray = File.ReadAllLines(@"puzzleconfig.csv");
int index = 1;
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 7; j++)
{
gameBoard[i, j] = (PictureBox)Controls.Find("pictureBox" +
(index).ToString(), true)[0];
index++;
}
}
int startingConfigIndex = 0;
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 7; j++)
{
gameBoard[i, j].BackColor =
Color.FromName(startingconfigarray[startingConfigIndex]);
startingConfigIndex++;
}
}
}
}