我在总结 DGV 中特定单元格中插入的两个值时遇到问题。这个过程发生在运行时。求和的结果应该显示在另一个特定的单元格中。
我试过下面的代码:
Private Sub dgdTax_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgdTax.CellContentClick
'======================================== CALCULATION ==============================================='
'to calculate r4rm1
Dim r2rm1 As Double
Dim r3rm1 As Double
Try
r2rm1 = CDbl(dgdTax(1, 2).Value)
Catch e1 As Exception
MessageBox.Show(e1.Message)
Exit Sub
End Try
Try
r3rm1 = CDbl(dgdTax(1, 3).Value)
Catch e2 As Exception
MessageBox.Show(e2.Message)
Exit Sub
End Try
dgdTax(1, 4).Value = r2rm1 + r3rm1
End Sub
但它没有用。它显示消息错误“从 DBNull 类型到 Double 类型的转换无效。”
我应该怎么办?