Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1187
Add total summary for column
posted

I am trying to add a total at the bottom of a sale amount column. I get the following exception on the last line of my code that adds the summary for that column.  I can't figure out why.  I want the summary to have a currency style for that column.

 === CODE ===

        With e.Layout
            .AutoFitStyle = AutoFitStyle.ExtendLastColumn
            .Scrollbars = Scrollbars.Automatic
            .ViewStyle = ViewStyle.SingleBand
            .Override.CellPadding = 3
            .Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Solid
            .Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.Solid
            .Override.CellAppearance.BorderColor = Color.Black
            .Override.RowAppearance.BorderColor = Color.Black
            .Override.CellClickAction = CellClickAction.EditAndSelectText
            .Bands(0).Columns("saleamount").AllowRowSummaries = AllowRowSummaries.True
            .Bands(0).Summaries.Add("saletotal", SummaryType.Sum, .Bands(0).Columns("saleamount"), SummaryPosition.UseSummaryPositionColumn)
            .Bands(0).Summaries(0).SummaryDisplayArea = SummaryDisplayAreas.BottomFixed
            .Bands(0).Summaries(0).DisplayFormat = "{0}"
            .Bands(0).Summaries(0).Appearance.BackColor = Color.White
            .Bands(0).Summaries(0).SummaryPositionColumn.Style = ColumnStyle.Currency   <-- exception thrown here

       End With

=== exception thrown === 

 System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  StackTrace:
       at frmOptionsDialog.grdOptions_InitializeLayout(Object sender, InitializeLayoutEventArgs e)
       at Infragistics.Win.UltraWinGrid.UltraGrid.OnInitializeLayout(InitializeLayoutEventArgs e)

  

Parents
  • 3707
    posted

    The secret of the format is in the summary DisplayFormat. Try this block of code out:

            With e.Layout
                .AutoFitStyle = AutoFitStyle.ExtendLastColumn
                .Scrollbars = Scrollbars.Automatic
                .ViewStyle = ViewStyle.SingleBand
                .Override.CellPadding = 3
                .Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Solid
                .Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.Solid
                .Override.CellAppearance.BorderColor = Color.Black
                .Override.RowAppearance.BorderColor = Color.Black
                .Override.CellClickAction = CellClickAction.EditAndSelectText
                .Bands(0).Columns("saleamount").AllowRowSummaries = AllowRowSummaries.True
                .Bands(0).Summaries.Add("saletotal", SummaryType.Sum, .Bands(0).Columns("saleamount"), SummaryPosition.UseSummaryPositionColumn)
                .Bands(0).Summaries(0).SummaryDisplayArea = SummaryDisplayAreas.BottomFixed
                .Bands(0).Summaries(0).DisplayFormat = "{0:$ #######.00}"
                .Bands(0).Summaries(0).Appearance.BackColor = Color.White
    
           End With
    
Reply Children