我试图通过单元格选择对一些列值进行求和(3列受影响)。它有效,但所有3列的树总和值始终相同。
我正在尝试这个:
Private Sub gvIktato_CustomSummaryCalculate(ByVal sender As Object, ByVal e As DevExpress.Data.CustomSummaryEventArgs) Handles gvIktato.CustomSummaryCalculate
Dim View As GridView = CType(sender, GridView)
If e.SummaryProcess = CustomSummaryProcess.Calculate Then
If View.IsCellSelected(e.RowHandle, gvIktato.Columns("NETTO")) Then e.TotalValue = Convert.ToDecimal(e.TotalValue) + Convert.ToDecimal(View.GetRowCellValue(e.RowHandle, "NETTO"))
If View.IsCellSelected(e.RowHandle, gvIktato.Columns("BRUTTO")) Then e.TotalValue = Convert.ToDecimal(e.TotalValue) + Convert.ToDecimal(View.GetRowCellValue(e.RowHandle, "BRUTTO"))
If View.IsCellSelected(e.RowHandle, gvIktato.Columns("SKONTO_OSSZEG")) Then e.TotalValue = Convert.ToDecimal(e.TotalValue) + Convert.ToDecimal(View.GetRowCellValue(e.RowHandle, "SKONTO_OSSZEG"))
End If
End Sub
我应该如何重写代码,以获得每列的正确总和值?
我知道,我应该以某种方式区分列,但是如何?
感谢。
答案 0 :(得分:0)
您需要使用CustomSummaryEventArgs.Item
属性
这是一个例子:
Private Sub gvIktato_CustomSummaryCalculate(ByVal sender As Object, ByVal e As DevExpress.Data.CustomSummaryEventArgs) Handles gvIktato.CustomSummaryCalculate
Dim item As GridSummaryItem = TryCast(e.Item, GridSummaryItem)
If item Is Nothing Then
Exit Sub
End If
Dim View As GridView = CType(sender, GridView)
Dim fieldName As String = item.FieldName
Select Case fieldName
Case "NETTO", "BRUTTO", "SKONTO_OSSZEG"
If e.SummaryProcess = CustomSummaryProcess.Calculate Then
If View.IsCellSelected(e.RowHandle, View.Columns(fieldName)) Then
e.TotalValue = Convert.ToDecimal(e.TotalValue) + Convert.ToDecimal(e.FieldValue)
End If
End If
End Select
End Sub