0

I'm trying to sum some column values via cell selection (3 columns are affected). It works, but the tree sum values are always the same for all the 3 columns.

I'm trying this:

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

How should I rewrite the code, that I get the correct sum values for each column?

I know, I should distinguish somehow between the columns, but how?

Thanks.

derstauner
  • 1,478
  • 2
  • 23
  • 44

1 Answers1

0

You need to use CustomSummaryEventArgs.Item property.
Here is example:

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
nempoBu4
  • 6,521
  • 8
  • 35
  • 40