设置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;
}
}

上一篇:C# DataGridView中指定的单元格不能编辑


下一篇:C#学习笔记——DataGridView功能总结