考虑以下代码:
公共类 CrewDatabaseForm
Public Shared CrewList As List(Of String)
Private Sub CrewDatabaseForm_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
Dim CL As New List(Of String)
If DataGridView1.Rows.Count = 2 Then CL.Add(DataGridView1.Rows(0).Cells(0).Value)
If DataGridView1.Rows.Count > 2 Then
For i As Integer = 0 To (DataGridView1.Rows.Count - 2)
CL.Add(DataGridView1.Rows(i).Cells(0).Value.ToString)
Next
End If
MessageBox.Show(DataGridView1.Rows.Count.ToString)
End Sub
Private Sub CrewDatabaseForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
结束类
--这个表格只是一个datagridview。每当我退出表单并开始 if 和 for 语句时,如果我在第一列中输入了一个值并且没有按下输入,则会发生错误:
“Stage Tally.exe 中发生了‘System.NullReferenceException’类型的异常,但未在用户代码中处理
附加信息:对象引用未设置为对象的实例。
如果有这个异常的处理程序,程序可以安全地继续。”