try
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0)
if (dataGridView2[e.ColumnIndex, e.RowIndex].ReadOnly)
e.CellStyle.BackColor = Color.Red;
if (e.ColumnIndex == 1)
if (dataGridView2[e.ColumnIndex, e.RowIndex].ReadOnly)
e.CellStyle.BackColor = Color.Black;
}