Reputation: 31
I am using DevExpress xtragrid that is bound to a data source... all is fine there. I am adding 1 unbound column (balance) that will hold the result of a calculation. The 'balance' column MUST recalculate when the debit and / or credit column changes anywhere in the grid. Given there may be a large amount of records I am hoping a loop statement will not be my only option. Rather I was hoping for a solution using the Expression editor.
example:
dr cr balance
100 0 100
0 50 50
0 45 5
Upvotes: 3
Views: 3833
Reputation: 8381
Add the following event to your form for the grid. The code is in VB.NET but it should be pretty easy to convert to any language
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
Upvotes: 4