Select Case e.DataCol.Name Case "金额","收付" Dim dr As DataRow Dim drs As List(of DataRow) dr = e.DataTable.Find("[_SortKey] < " & e.DataRow("_SortKey"), "[_SortKey] Desc") '找出上一行 If dr Is Nothing Then '如果没有找到上一行,说明本行就是第一行 If e.DataRow("收付") = "收" Then e.DataRow("帐户余额") = e.DataRow("金额") End If If e.DataRow("收付") = "付" Then e.DataRow("帐户余额") = -e.DataRow("金额") End If dr = e.DataRow End If MessageBox.Show(dr("帐户")) drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [帐户] = '" & dr("帐户") & "'" ,"[_SortKey]") For i As Integer = 1 To drs.Count - 1 '重算余下行的余额 If drs(i)("收付") = "收" Then drs(i)("帐户余额") = drs(i-1)("帐户余额") + drs(i)("金额") End If If drs(i)("收付") = "付" Then drs(i)("帐户余额") = drs(i-1)("帐户余额") - drs(i)("金额") End If Next End Select
|