对 c#winform datagridview 单个单元格的控制(改变单个单元格的背景色)

private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
if (dgr.Cells["onduty1"].Value.ToString() == "" || dgr.Cells["onduty1"].Value.ToString() == null)
{
dgr.Cells["onduty1"].Style.BackColor = Color.Red;
}
 
}
catch (Exception ex)
{

 MessageBox.Show(ex.Message);
}
}

posted @ 2017-02-27 16:46  小小程序媛1116  阅读(6587)  评论(0编辑  收藏  举报