这可能是一个很长的问题,但请耐心等待。
我Datagridview1
对Form1
列有意见BranchCode("cells(2) ,FormCode("cells(3)")), Quantity("cells(5)")
现在让我们说这就是它的样子
DGV1
BranchCode | FormCode | Quantity
001 Frm1 10
002 Frm2 -10
001 Frm1 20
现在在 DGV2 上,假设我有一个具有相同分支代码和表单代码的数据
DGV2
BranchCode | FormCode | Quantity
001 Frm1 50
002 Frm2 50
现在下面的代码循环然后在添加之前DGV1
总结所有Quantity
相同 的FormCode and BranchCode
DGV2
例如:DGV1 结果
BranchCode | FormCode | Quantity
001 Frm1 30
002 Frm2 -10
然后将其添加到 DGV2 后,这将是结果
DGV 2 结果
BranchCode | FormCode | Quantity
001 Frm1 80
002 Frm2 40
代码
For Each xRows In MDIAdjustment.oTransferRows.Where(Function(x) x.Cells("GVPosted").Value.ToString() = "No")
If (occurences.ContainsKey(xRows.Cells(3).Value.ToString())) Then
occurences(xRows.Cells(3).Value.ToString()).Quantity = Double.Parse(occurences(xRows.Cells(3).Value.ToString()).ToString()) + Double.Parse(xRows.Cells(5).Value.ToString())
Else
occurences.Add(xRows.Cells(3).Value.ToString(), New CustomValues2 With {.Code = xRows.Cells(3).Value.ToString(), .Branch = xRows.Cells(2).Value.ToString(), .Description = xRows.Cells(4).Value.ToString(), .Quantity = Double.Parse(xRows.Cells(5).Value.ToString()) })
End If
Next
宣言occurences dictionary
Dim occurences As New Dictionary(Of String, CustomValues2)
Class CustomValues2
Public Property Code() As String
Public Property Branch() As String
Public Property Description() As String
Public Property Quantity() As Double
End Class
问题是,当我只使用正整数进行计算时,我没有问题,但是当我开始添加负数时,我在这一行出现错误
occurences(xRows.Cells(3).Value.ToString()).Quantity = Double.Parse(occurences(xRows.Cells(3).Value.ToString()).ToString()) + Double.Parse(xRows.Cells(5).Value.ToString())
说FormatException was Unhandled" Input string was not in a correct format
对不起,对于长篇文章,我已经尝试过做一些事情,但他们并没有消除错误。