我正在使用绑定到数据源的DevExpress xtragrid ......一切都很好。我正在添加1个未绑定的列(余额),它将保存计算结果。当借方和/或信用列在网格中的任何位置发生变化时,“余额”列必须重新计算。鉴于可能存在大量记录,我希望循环语句不是我唯一的选择。相反,我希望有一个解决方案使用 表达式编辑器。
示例:
dr cr balance
100 0 100
0 50 50
0 45 5
答案 0 :(得分:4)
将以下事件添加到网格的表单中。代码在VB.NET中,但转换为任何语言都很容易
Private Sub gridView_CustomUnboundColumnData(sender As System.Object, e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Handles
gvCash.CustomUnboundColumnData
Dim view = DirectCast(sender, GridView)
If e.Column.FieldName = "colRunningBalance" And e.IsGetData Then
Dim total = 0D
For i As Integer = -1 To e.ListSourceRowIndex - 1
total += CDec(view.GetListSourceRowCellValue(i + 1, "Amount"))
Next
e.Value = total
End If
End Sub