You can bind at RowsAdded event.
void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
foreach (DataGridViewCell item in dataGridView1.Rows[e.RowIndex].Cells)
{
if (item.Value.GetType() == typeof(int))
{
if ((int)item.Value > 50)
{
item.Style.BackColor = Color.Red;
}
}
}
}
You can also do that for the CellEndEdit event if you want to check everytime user edit a cell.
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewCell item in dataGridView1.Rows[e.RowIndex].Cells)
{
int value;
if (int.TryParse((string)item.Value,out value))
{
if (value > 50)
{
item.Style.BackColor = Color.Red;
}
else
{
item.Style.BackColor = Color.Green;
}
}
}
}