Vb.net 将datagridview数据传递给另一个datagridview';System.NullReferenceException';
我需要帮助解决这个问题,但我不知道如何解决这个问题 这就是代码Vb.net 将datagridview数据传递给另一个datagridview';System.NullReferenceException';,vb.net,Vb.net,我需要帮助解决这个问题,但我不知道如何解决这个问题 这就是代码 Private Sub GetLabandOtherFees() Dim dic As New Dictionary(Of String, Integer)() Dim cellValue As String = Nothing For i As Integer = 0 To dgvSubjectsEnrolled.Rows.Count - 1 If Not d
Private Sub GetLabandOtherFees()
Dim dic As New Dictionary(Of String, Integer)()
Dim cellValue As String = Nothing
For i As Integer = 0 To dgvSubjectsEnrolled.Rows.Count - 1
If Not dgvSubjectsEnrolled.Rows(i).IsNewRow Then
cellValue = dgvSubjectsEnrolled(0, i).Value.ToString()
If Not dic.ContainsKey(cellValue) Then
dic.Add(cellValue, 1)
Else
dic(cellValue) += 1
End If
End If
Next
Dim sb As New StringBuilder()
For Each keyvalue As KeyValuePair(Of String, Integer) In dic
sb.AppendLine(String.Format("{0}", keyvalue.Key, keyvalue.Value))
Next
For Each row As DataGridViewRow In dgvsub.Rows
row.Cells(0).Value = sb.ToString()
row.Cells(1).Value = dic.Count.ToString()
Next
End Sub
这就是错误
"Object Reference Not set to an instance of an object."
Check to determine if object is null before calling the method.
这个错误使我头痛。请帮助。阅读错误内容。在这里,试试这个,只需在其中添加一点条件
If dgvSubjectsEnrolled(0, i).Value > 0 Then
cellValue = dgvSubjectsEnrolled(0, i).Value.ToString()
If Not dic.ContainsKey(cellValue) Then
dic.Add(cellValue, 1)
Else
dic(cellValue) += 1
End If
Else
End If
在这段代码中,错误发生在什么地方?错误看起来是什么样子?这部分。“cellValue=dgvSubjectsEnrolled(0,i).Value.ToString()”是的!谢谢。干得好。。