【发布时间】:2012-03-21 08:40:09
【问题描述】:
我正在尝试使用我的 DataGridView 值加载我的文本框,如下所示,但我得到了 “在 Microsoft.VisualBasic.dll 中发生了‘System.NullReferenceException’类型的第一次机会异常” 错误,尽管如此,该程序仍然可以使用。有谁知道出了什么问题?
非常感谢。
代码:
For iloop = 0 To DataGridView2.Rows.Count
For Each cCtrl As Control In Panel2.Controls
If TypeOf cCtrl Is TextBox Then
Dim txtBox As TextBox
txtBox = cCtrl
If (txtBox.Name.Substring(9, 6)) = ((DataGridView2.Rows.Item(iloop).Cells(0).Value).substring(0, 6)) Then
txtBox.Text = DataGridView2.Rows.Item(iloop).Cells(3).Value
End If
End If
Next
Next
【问题讨论】:
-
哪一行出现错误?
-
嗨,这一行是:“If (txtBox.Name.Substring(9, 6)) = ((DataGridView2.Rows.Item(iloop).Cells(0).Value).substring( 0, 6)) Then" ((DataGridView2.Rows.Item(iloop).Cells(0).Value).substring(0, 6)) 实际上是导致它的原因。