当datagridview某单元格为空的时候,要是dgvSO.Rows[i].Cells[0].Value.ToString() == ""判断的话,会报“未将对象实例化”的异常。

解决方案 »

  1.   

    if(dgvSO.Rows[i].Cells[0].Value IS NULL || dgvSO.Rows[i].Cells[0].Value.ToString() == "")
      

  2.   

    //C#应该这样写
    if(dgvSO.Rows[i].Cells[0].Value == null || dgvSO.Rows[i].Cells[0].Value.ToString() == "") 
      

  3.   

    if(dgvSO.Rows[i].Cells[0].Value!=null&&!string.IsNullOrEmpty(dgvSO.Rows[i].Cells[0].Value.ToString())
    {}
      

  4.   

    dgvSO.SelectRows[i].Cells[0].Value.ToString() == ""
    设置单行选择就不需要判断null了
      

  5.   

    if(dgvSO.Rows[i].Cells[0].Value!= null&&dgvSO.Rows[i].Cells[0].Value.ToString() != "")