Select Case e.DataCol.Name
Case "供应商编码","借方","贷方"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [供应商编码] = \'" & mr("供应商编码") & "\'", "[_SortKey] Desc")
If dr Is Nothing Then \'如果没有上一行,说明本行就是同产品的第一行
mr("余额") = mr("借方") - mr("贷方")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [供应商编码] = \'" & dr("供应商编码") & "\'")
For i As Integer = 1 To drs.Count - 1 \'重算余下行的余额
drs(i)("余额") = drs(i-1)("余额") + drs(i)("借方") - drs(i)("贷方")
Next
End Select