I setup a header aggregate in a grouping but it seems to be coming up with the wrong sum total. Screenshot attached.
Very strange that the footer aggregates come up with the right total, but the header doesn't. Below is how I'm setting up the structure of the grid columns.
Very strange that the footer aggregates come up with the right total, but the header doesn't. Below is how I'm setting up the structure of the grid columns.
Private Sub BuildDataGrid(ByVal view As Views) Try Dim addColumn As Action(Of GridColumn) = Sub(column) BottomSection(Of TMGrid)("dgView").MasterTableView.Columns.Add(column) Dim addToGrouping As Action(Of GridColumn) = Sub(column) BottomSection(Of TMGrid)("dgView").MasterTableView.GroupByExpressions.Add( New GridGroupByExpression(column) ) End Sub With BottomSection(Of TMGrid)("dgView") .MasterTableView.Columns.Clear() .MasterTableView.GroupByExpressions.Clear() Select Case view Case Views.Daily TMGrid.AddBoundColumn( addColumn, Function() "tl_date", Function() "Date", Function() False, Function() "{0:MMMM d}", Sub(column) Dim grouping As New GridGroupByExpression() Dim selectDate As New GridGroupByField() selectDate.FieldName = "tl_date" selectDate.FieldAlias = "tl_date" selectDate.FormatString = TMGrid.SHORT_DATE_FORMAT selectDate.HeaderText = "DATE" selectDate.HeaderValueSeparator = ": " Dim selectTotalHours As New GridGroupByField() selectTotalHours.FieldName = "te_hours" selectTotalHours.FieldAlias = "te_hours" selectTotalHours.HeaderText = "TOTAL HOURS" selectTotalHours.Aggregate = GridAggregateFunction.Sum selectTotalHours.FormatString = TMGrid.HOURS selectTotalHours.HeaderValueSeparator = ": " Dim groupByDate As New GridGroupByField() groupByDate.FieldName = "tl_date" groupByDate.FieldAlias = "tl_date" grouping.SelectFields.Add(selectDate) grouping.SelectFields.Add(selectTotalHours) grouping.GroupByFields.Add(groupByDate) 'grouping.Expression = "tl_date [Date], Sum(te_hours) TotalHours [Total Hours] Group By tl_date" BottomSection(Of TMGrid)("dgView").MasterTableView.GroupByExpressions.Add(grouping) End Sub ) TMGrid.AddBoundColumn( addColumn, Function() "tc_name", Function() "ACTIVITY", AddressOf RequireSubactivity, Nothing, addToGrouping ) TMGrid.AddBoundColumn( addColumn, Function() "tsc_name", Function() "SUBACTIVITY" ) TMGrid.AddBoundColumn( addColumn, Function() "te_desc", Function() "DESCRIPTION" ) TMGrid.AddBoundColumn( addColumn, Function() "te_hours", Function() "HOURS", Function() True, Function() "<a href='{0}'>{0:#0.00}</a>", Sub(column) column.ItemStyle.HorizontalAlign = HorizontalAlign.Right column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right column.FooterStyle.HorizontalAlign = HorizontalAlign.Right column.Aggregate = GridAggregateFunction.Sum column.FooterAggregateFormatString = "Total: {0:#0.00}" End Sub ) Case Views.Monthly TMGrid.AddBoundColumn( addColumn, Function() "tl_monthname", Function() "Month", Function() False, Nothing, addToGrouping ) TMGrid.AddBoundColumn( addColumn, Function() "tc_name", Function() "ACTIVITY", AddressOf RequireSubactivity, Nothing, addToGrouping ) TMGrid.AddBoundColumn( addColumn, Function() "tsc_name", Function() "SUBACTIVITY" ) TMGrid.AddBoundColumn( addColumn, Function() "te_desc", Function() "DESCRIPTION" ) If (Convert.ToInt32(ViewState("ReportingMode")) = TMTERMSOptions.TMTERMSReportingModes.Daily) Then TMGrid.AddBoundColumn( addColumn, Function() "te_hours", Function() "HOURS", Function() True, Function() "{0:#0.00}", Sub(column) column.ItemStyle.HorizontalAlign = HorizontalAlign.Right column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right column.FooterStyle.HorizontalAlign = HorizontalAlign.Right column.Aggregate = GridAggregateFunction.Sum column.FooterAggregateFormatString = "Total: {0:#0.00}" End Sub ) Else TMGrid.AddBoundColumn( addColumn, Function() "te_hours", Function() "HOURS", Function() True, Function() "<a href='{0}'>{0:#0.00}</a>", Sub(column) column.ItemStyle.HorizontalAlign = HorizontalAlign.Right column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right column.FooterStyle.HorizontalAlign = HorizontalAlign.Right column.Aggregate = GridAggregateFunction.Sum column.FooterAggregateFormatString = "Total: {0:#0.00}" End Sub ) End If TMGrid.AddBoundColumn( addColumn, Function() "certified_message", Function() "CERTIFICATION" ) TMGrid.AddBoundColumn( addColumn, Function() "approved_message", Function() "APPROVAL" ) TMGrid.AddBoundColumn( addColumn, Function() "te_approved_hours", Function() "APPROVED HOURS", Function() "{0:#,##0.00}" ) Case Views.Annual TMGrid.AddBoundColumn( addColumn, Function() "tl_year", Function() "YEAR", Function() False, Nothing, addToGrouping ) TMGrid.AddBoundColumn( addColumn, Function() "tc_name", Function() "YEAR / ACTIVITY", AddressOf RequireSubactivity, Nothing, addToGrouping ) TMGrid.AddBoundColumn( addColumn, Function() "tsc_name", Function() "YEAR / ACTIVITY / SUBACTIVITY" ) TMGrid.AddBoundColumn( addColumn, Function() "te_hours", Function() "HOURS", Function() "{0:#,##0.00}" ) End Select End With Catch ex As Exception Throw New Exception("BuildDataGrid procedure failed", ex) End TryEnd Sub