Current filter:
                                You should refresh the page.
                                  • I have an ASPxGridView control, that gets it’s data and columns at runtime from a stored procedure.  The stored procedure does a pivot, and so some of the columns are not known until runtime.
                                    When calculating totals for a given column,  I need to be able to customize the total at runtime, excluding some values, based upon another column’s data value.
                                    I have this event code, but the event does not fire!

                                    [VB.NET]
                                    Protected Sub ASPxGridView1_CustomSummaryCalculate(sender As Object, e As DevExpress.Data.CustomSummaryEventArgs) Handles ASPxGridView1.CustomSummaryCalculate Dim summary As ASPxSummaryItem = TryCast(e.Item, ASPxSummaryItem) If summary.FieldName = "ProductItemKey" Or summary.FieldName = "RowTotal" Then Return End If If e.IsTotalSummary Then Dim totalValue As Integer = 0 For Each value As Object In ASPxGridView1.GetSelectedFieldValues("Quantity") totalValue += Convert.ToInt32(value) Next value e.TotalValue = totalValue e.TotalValueReady = True End If End Sub
                                • MILES GIBSON 12.02.2019

                                  UPDATE:

                                  I got the CustomSummaryCalculate event to fire. I changed the Summary Type to Custom here:

                                  [VB.NET]
                                  Protected Sub ASPxGridView1_DataBound(sender As Object, e As EventArgs) Handles ASPxGridView1.DataBound Dim colTotal As ASPxSummaryItem Dim summaryItemType As DevExpress.Data.SummaryItemType = DevExpress.Data.SummaryItemType.Custom Dim bFound As Boolean If Me.IsPostBack = False Then For Each col As GridViewDataColumn In ASPxGridView1.Columns bFound = False For Each item As ASPxSummaryItem In ASPxGridView1.TotalSummary.GetVisibleItems If item.Tag = col.FieldName Then bFound = True Exit For End If Next If col.Visible AndAlso col.FieldName <> "ProductItemKey" AndAlso col.FieldName <> "IncludeInBoxCount" AndAlso col.FieldName <> "IsSourceForPackout" Then colTotal = New ASPxSummaryItem(col.FieldName, summaryItemType) colTotal.Tag = col.FieldName ASPxGridView1.TotalSummary.Add(colTotal) End If Next End If End Sub

                                  HOWEVER:  In order to calculate the total that I want (by excluding certain values), I need to look at the current column of data to sum it, and also to examine the value of an adjacent column.  So I guess I would want to loop through all of the values for Column X, and only sum it if Column Y-value is checked or not (in this case a boolean).

                                  SO: What is the best approach?  How to retrieve all of the values for any given column, for all visible rows (or all rows)?

                                  TIA,

                                • Oleg (DevExpress Support) 12.03.2019

                                  Hello Miles,
                                  Would you please provide more details about your scenario? I see that you used the GetSelectedFieldValues method in the CustomSummaryCalculate event handler to exclude specific rows while calculating summaries.
                                  This method returns values only for rows that were selected by an end user, however I do not see a command column with the "Select" checkbox in your document's screenshot.
                                  Also, in your document you mentioned that you are using a hidden checkbox column to exclude rows. Thus, please clarify what your current scenario is. Do you need to operate rows selected by an end user or with rows that have specific values in hidden columns?
                                  In the second case, clarify if these columns are created as unbound columns or these column values are obtained from your data source.

                                  This information will help us better understand your task and find the most appropriate solution.

                                • MILES GIBSON 12.03.2019

                                  Hi Oleg,
                                  I actually need to provide totals for the entire dataset, which will almost always be one page.  The GetSelectedFieldValues was just one of the methods I was trying as I didn't see a method for returning values for a specific column.  After my support posting, I found ASPxGridView1.GetCurrentPageRowValues(fieldNames.ToArray()), but it presumes totals by page, and it also pulls all data.  That may work, except that I would have to determine the index number for the current column to pull data out of the data matrix that this method returns.

                                  When the event grid_CustomSummaryCalculate fires, is it on a column by column basis?  My client wants certain values excluded from the column grand totals.  So when totaling the values for a given column, I need to be able to look at a hidden column to determine whether to exclude that value from the overall column total.  Make sense?

                                  There should be a ASPxGridView1.GetColumnValues(colNumber, fieldNames.ToArray()) function..

                                  TIA,

                                • MILES GIBSON 12.03.2019

                                  So this works:

                                   Protected Sub grid_CustomSummaryCalculate(sender As Object, e As DevExpress.Data.CustomSummaryEventArgs) Handles ASPxGridView1.CustomSummaryCalculate

                                          Dim summary As ASPxSummaryItem
                                          Dim list As List(Of Object)
                                          Dim listIncludeInBoxCount As List(Of Object)
                                          Dim listIsSourceForPackout As List(Of Object)

                                          Try
                                              summary = TryCast(e.Item, ASPxSummaryItem)
                                              If summary.FieldName = "ProductItemKey" Or summary.FieldName = "RowTotal" Then
                                                  Return
                                              End If

                                              list = GetColumnValues(summary.Tag)
                                              listIncludeInBoxCount = GetColumnValues("IncludeInBoxCount")
                                              listIsSourceForPackout = GetColumnValues("IsSourceForPackout")

                                              If e.IsTotalSummary Then
                                                  Dim totalValue As Integer = 0
                                                  For x As Integer = 0 To list.Count - 1
                                                      If CBool(listIncludeInBoxCount(x)) = True And CBool(listIsSourceForPackout(x)) = False Then
                                                          If IsDBNull(list(x)) = False Then
                                                              totalValue += Convert.ToInt32(list(x))
                                                          End If
                                                      End If

                                                  Next
                                                  e.TotalValue = totalValue
                                                  e.TotalValueReady = True
                                              End If
                                          Catch ex As ArgumentNullException

                                          End Try

                                      End Sub
                                      Private Function GetColumnValues(pstrFieldName As String) As List(Of Object)

                                          Return ASPxGridView1.GetCurrentPageRowValues(pstrFieldName)
                                      End Function

                                1 Solution

                                Creation Date Importance Sort by

                                So this works:

                                [VB.NET]
                                Protected Sub grid_CustomSummaryCalculate(sender As Object, e As DevExpress.Data.CustomSummaryEventArgs) Handles ASPxGridView1.CustomSummaryCalculate Dim summary As ASPxSummaryItem Dim list As List(Of Object) Dim listIncludeInBoxCount As List(Of Object) Dim listIsSourceForPackout As List(Of Object) Try summary = TryCast(e.Item, ASPxSummaryItem) If summary.FieldName = "ProductItemKey" Or summary.FieldName = "RowTotal" Then Return End If list = GetColumnValues(summary.Tag) listIncludeInBoxCount = GetColumnValues("IncludeInBoxCount") listIsSourceForPackout = GetColumnValues("IsSourceForPackout") If e.IsTotalSummary Then Dim totalValue As Integer = 0 For x As Integer = 0 To list.Count - 1 If CBool(listIncludeInBoxCount(x)) = True And CBool(listIsSourceForPackout(x)) = False Then If IsDBNull(list(x)) = False Then totalValue += Convert.ToInt32(list(x)) End If End If Next e.TotalValue = totalValue e.TotalValueReady = True End If Catch ex As ArgumentNullException End Try End Sub Private Function GetColumnValues(pstrFieldName As String) As List(Of Object) Return ASPxGridView1.GetCurrentPageRowValues(pstrFieldName) End Function
                                • Oleg (DevExpress Support) 12.04.2019

                                  Hello Miles,
                                  Thank you for informing me that you have found a way to implement the required behavior.

                                  In case your data source records are located on several Grid View pages, you can use the ASPxGridView.VisibleRowCount property  to obtain the row count on the server side and the ASPxGridView.GetRowValues method to get required values.
                                  Please refer to the following topic:
                                  Traversing Rows

                                  and the following thread:
                                    ASPxGridView - How to iterate through all rows

                                  Do not hesitate to contact me if you have additional questions or need further assistance.