private void dataGridView_C_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
if (e != null)
{
if (dataGridView_C.Rows[e.RowIndex].Cells["xx"].Value.ToString() != "1")
{
dataGridView_C.Rows[e.RowIndex].Cells["xxx"].Style.ForeColor = Color.Red;
}
else
{
dataGridView_C.Rows[e.RowIndex].Cells["xxx"].Style.ForeColor = Color.Black;
}
}
} 开始运行正常,当滚动条移动时,发现会产生: “e.RowIndex”引发了“System.NullReferenceException”类型的异常 ,跟踪程序发现 e 的所有属性都为空,但 e 不为空 ,在这里如何控制这个异常的发生
{
if (e != null)
{
if (dataGridView_C.Rows[e.RowIndex].Cells["xx"].Value.ToString() != "1")
{
dataGridView_C.Rows[e.RowIndex].Cells["xxx"].Style.ForeColor = Color.Red;
}
else
{
dataGridView_C.Rows[e.RowIndex].Cells["xxx"].Style.ForeColor = Color.Black;
}
}
} 开始运行正常,当滚动条移动时,发现会产生: “e.RowIndex”引发了“System.NullReferenceException”类型的异常 ,跟踪程序发现 e 的所有属性都为空,但 e 不为空 ,在这里如何控制这个异常的发生
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货