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)
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
I'm not sure why you are getting that Exception. When the exception occurs, what object is null?
In any case, Torrey is correct. Setting the Style on column won't do anything to the summary, anyway, it will only affect the column itself.