DataGridViewCellStyle style = new DataGridViewCellStyle();
                                                     foreach ( DataGridViewRow aRow in dataGridView3.Rows)
                            {
                                if (aRow.Cells["message"].Value.ToString() == "不存数据")(未将对象引用设置到对象的实例)
                                {
                                    aRow.DefaultCellStyle.ForeColor = Color.Red;                                }
                            } 
上面提示,使用NEW关键字创建实例,该怎么样修改,谢谢

解决方案 »

  1.   

               if(!string.IsNullOrEmpty(aRow.Cells["message"].Value))
      

  2.   

    aRow.Cells["message"]
    有没有这么一列。
      

  3.   

    回楼上,有的改成cells[2]也出错,但是第三列,有些数据是NULL的.
      

  4.   

    if (aRow.Cells["message"] != null)
        if (aRow.Cells["message"].Value != null)
            if (aRow.Cells["message"].Value.ToString() == "不存数据")
                aRow.DefaultCellStyle.ForeColor = Color.Red;