I’m getting a frustrating error that I’m pretty sure is something simple, but I cannot figure out what.
Here is my function:
public void setDistanceCellValue(int value, int row, int column)
{
try
{
Console.WriteLine("Row: " + row + " Column: " + column + " Value: " + value);
logGrid.Rows[row].Cells[column].Value = value.ToString();
}
catch (Exception ex)
{
MessageBox.Show(string.Format("An error occurred: {0}" + "\r\n" + "\r\n" + "Row: " + row + " Column: " + column + " Value: " + value, ex.Message));
}
}
Where the logGrid value setting line is what is erroring out with “Index is out of range. Must be non-negative and less than the size of the collection. Parameter name: index.”
I’ve been checking and checking and my grid has six rows and 8 columns, and the function is getting called on say row 2 column 3 (hence all the debugging code). For the life of my I can’t figure out why it is saying I’m using a negative index or an index large than 5 for the e.rowIndex or 7 for e.columnIndex.
Help me if you can.
The indexes range from 0 to N-1, not from 1 to N.
EDIT:
Two suggestions
Console.WriteLineAutoGenerateColumnsproperty to see if it set as you expected.