I have a 2D array. I want to print the array in my DataGridView
but it throws an error:
[Argument OutOfRangeException was unhandled ] >
The first potential problem is with how you are accessing your array indexes. Which can be handled this way.
string[,] a = {
{"0", "1", "2"},
{"0", "1", "2"},
{"0", "1", "2"},
{"0", "1", "2"},
};
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
Console.WriteLine(a[i,j]);
}
}
Just check your array dimension length first. Clearly one of your variables height or width is incorrect.
This is done using Array.GetLength(int dimension)
The second problem is how you are adding items to your datagridview.