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
e.DataRow("余额") = e.DataRow("收入") - e.DataRow("支出")
dr = e.DataRow
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey"), "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("余额") = drs(i-1)("余额") + drs(i)("收入") - drs(i)("支出")
Next
问题就可以解决,就不会出错了。不知这个办法是否可行?是不是还有更好的办法?