How to change row color in datagridview?

You need to loop through the rows in the datagridview and then compare values of columns 7 and 10 on each row.

Try this:

foreach (DataGridViewRow row in vendorsDataGridView.Rows) 
     if (Convert.ToInt32(row.Cells[7].Value) < Convert.ToInt32(row.Cells[10].Value)) 
     {
         row.DefaultCellStyle.BackColor = Color.Red; 
     }

Leave a Comment