当前位置:编程学习 > C#/ASP.NET >>

未将对象引用设置到对象的实例,请问如何处理,谢谢

xxbh1 = DataGridView3.Rows(e.RowIndex).Cells(0).Value.ToString
“未将对象引用设置到对象的实例” 请问下如何处理 --------------------编程问答-------------------- DataGridView3.Rows(e.RowIndex).Cells(0).Value
e.RowIndex
DataGridView3.Rows(e.RowIndex).
DataGridView3.Rows(e.RowIndex).Cells(0)

这四个反正有一个是null, --------------------编程问答-------------------- 很简单,将断点设在这句上,
在debug调试中打入:
    ?DataGridView1.Rows.Count 
  看看有没有row存在 
如果有,再debug调试中打入:
  ?DataGridView1.Rows(0).Cells.Count 
 看看有没有cell存在 
估计是没有Rows,可能你还没有给 DataGridView1赋值。 --------------------编程问答-------------------- 通常,DataGridView的Cell的Value不会是Nothing,只可能是Null,用ToString可以转为空字符串。
而其他对象则可能是Nothing,而不会是Null。


If Not e Is Nothing Then
  If Not e.RowIndex Is Nothing Then
    If Not DataGridView3 Is Nothing Then
      If Not DataGridView3.Rows(e.RowIndex) is Nothing Then
        If Not DataGridView3.Rows(e.RowIndex).Cells(0) Is Nothing Then
          xxbh1 = DataGridView3.Rows(e.RowIndex).Cells(0).Value.ToString
        End If
      End If
    End If
  End If
End If
--------------------编程问答-------------------- 你可以像楼上那样,判断每一种情况是否为空,然后再赋值 --------------------编程问答-------------------- debug才是王道... --------------------编程问答-------------------- --------------------编程问答-------------------- 设置断点调试就晓得了撒,LZ try again! --------------------编程问答-------------------- 有空数据了,
设个断点看看。
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,