Try this:
var mylist = new[] {
new{ A = 1, B = 1},
new {A = 2, B = 2},
new {A = 3, B = 2},
new {A = 4, B = 4}};
dataGridView1.DataSource = mylist;
Load += (sender, e) =>
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if((int)row.Cells["A"].Value != (int)row.Cells["B"].Value)
row.DefaultCellStyle.BackColor = Color.Red;
}
};
Please remember that, the DefaultCellStyle.BackColor is set successfully for a particular row of datagridview only when the form is loaded. I searched for this before posting my code here for you.
Hope it helps!