设置DataGridView的单元格颜色

RowPrePaint事件:

private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)

{
if ("不存在" == this.dataGridView1.Rows[e.RowIndex].Cells["库位"].Value.ToString())
{
this.dataGridView1.Rows[e.RowIndex].Cells["库位"].Style.BackColor = Color.MediumPurple;
}
}

原文地址:https://www.cnblogs.com/roak/p/14148013.html