答案 0 :(得分:0)
这是一个简单的例子:
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
DataGridView dgv = dataGridView1;
if (e.ColumnIndex < 0 || e.RowIndex < 0) return;
if (dgv[0, e.RowIndex].Value == null ||dgv[1, e.RowIndex].Value == null) return;
// assuming integers, adapt to real types and real column indices!
dgv[1, e.RowIndex].Style.BackColor =
(int)dgv[0, e.RowIndex].Value < (int)dgv[1, e.RowIndex].Value ?
Color.LightSalmon : dgv.DefaultCellStyle.BackColor;
}