考虑以下代码:
Public Class 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'类型的异常,但未在用户代码中处理
附加信息:未将对象引用设置为对象的实例。
如果存在此异常的处理程序,则可以安全地继续该程序。“