Change your code from
for (int i = 0; i < 4; i++)
To
for (int i = 0; i < datagridView.RowCount; i++)
It looks as though your data grid view has no rows in it and you are making the assumption that there will always be 4 rows. Doing .RowCount will use the number of rows in your data grid view and loop through that, handle any other logic to do first four rows within for loop.
Full snippet
int iRow = 0;
for (int i = 0; i < datagridView.RowCount; i++)
{
datagridView.Rows[iRow].DefaultCellStyle.ForeColor = Color.blue;
datagridview.rows[iRow].DefaultCellStyle.Backcolor = color.bisque;
iRow = iRow + 1;
}