参考代码
Select Case e.DataCol.name
Case "第一列","第二列", "第三列"
Dim drs As List(of DataRow)
Dim Filter As String
filter = "[第一列] = '" & e.DataRow("第一列") & "' and 第二列 = '" & e.DataRow("第二列") & "'"
Dim qc As Double = 0
Dim fdr As DataRow = DataTables("表A").Find(filter)
If fdr IsNot Nothing Then
qc = fdr("第三列")
End If
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 [第一列] = '" & e.DataRow("第一列") & "' and 第二列 = '" & e.DataRow("第二列") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(第三列)",Filter)
dr("第四列") = qc - Val1
Next
If (e.DataCol.name = "第一列" OrElse e.DataCol.name = "第二列") And e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
If e.DataCol.Name = "第一列" Then
Filter = "[第一列] = '" & e.oldvalue & "' and 第二列 = '" & e.DataRow("第二列") & "'"
ElseIf e.DataCol.name = "第二列" Then
Filter = "[第一列] = '" & e.DataRow("第一列") & "' and 第二列 = '" & e.oldvalue & "'"
End If
drs = e.DataTable.Select("[_SortKey] > " & e.DataRow("_SortKey") & " and " & Filter)
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And " & filter
Dim Val1 As Double = e.DataTable.Compute("Sum(第三列)",Filter)
dr("第四列") = Val1
Next
End If
End Select