试试
Select Case e.DataCol.Name
Case "品名","型号规格", "数量"
Dim drs As List(of DataRow)
Dim Filter As String
Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [品名] = '" & e.DataRow("品名") & "' and 型号规格 = '" & e.DataRow("型号规格") & "'"
drs = e.DataTable.Select(Filter)
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And [品名] = '" & dr("品名") & "' and 型号规格 = '" & dr("型号规格") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(数量)",Filter)
dr("本品名型号规格累计") = Val1
Next
Filter = ""
If e.DataCol.Name = "品名" AndAlso e.OldValue IsNot Nothing Then
Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [品名] = '" & e.OldValue & "' and 型号规格 = '" & e.DataRow("型号规格") & "'"
ElseIf e.DataCol.Name = "型号规格" AndAlso e.OldValue IsNot Nothing Then
Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [品名] = '" & e.DataRow("品名") & "' and 型号规格 = '" & e.OldValue & "'"
End If
If Filter > "" Then
drs = e.DataTable.Select(Filter)
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And [品名] = '" & dr("品名") & "'and 型号规格 = '" & dr("型号规格") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(数量)",Filter)
dr("本品名型号规格累计") = Val1
Next
End If
End Select