バージョン

Add(SummaryType,ICustomSummaryCalculator,UltraGridColumn,SummaryPosition,UltraGridColumn) メソッド

指定した引数を使用して作成された新しいSummarySettingsオブジェクトを追加し、そのSummarySettingsオブジェクトを返します。
シンタックス

パラメータ

summaryType
SummaryType。Custom を指定する場合、有効なインスタンス ICustomSummaryCalculator は customSummaryCalculator として渡される必要があります。
customSummaryCalculator
SummaryType が Custom である場合に限って要求されます。
sourceColumn
集計されるフィールド。
summaryPosition
集計がグリッドで表示される場所を指定します。
summaryPositionColumn
summaryPosition が UseSummaryPositionColumn である場合に限って要求されます。

戻り値の型

新しい SummarySettings オブジェクトを作成し、それを提供される引数と共にコレクションに追加します。
解説

渡された引数に基づいて新しいSummarySettingsオブジェクトを作成し、それをコレクションに追加します。

summaryType が SummaryType.Custom の場合は、customSummaryCalculator 引数に ICustomSummaryCalculator の有効なインスタンスを渡す必要もあります。summaryType が Custom 以外の場合、このパラメーターは必要でないため、null を指定できます。

summaryPosition が SummaryPosition.UseSummaryPositionColumn の場合、集計はsummaryPositionColumn 列の下に表示されます。summaryPositionColumnが指定されていない場合は、ソース列の下に表示されます。この列は、このSummaryCollectionが関連付けられているバンドの列である必要があります。summaryPosition が UseSummaryPositionColumn 以外の場合、summaryPositionColumn パラメーターは必要でないため、null を指定できます。

SourceColumn には、集計対象のデータを含む列を指定します。sourceColumn は、この SummarySettingsCollection に関連付けられたバンドか、その子孫バンドの列である必要があります。

使用例
Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  ' A class that calculates the totals for orders.
  Private Class OrderTotalsSummary
      Implements ICustomSummaryCalculator

      Private totals As Decimal = 0

      Public Sub New()
      End Sub

      Private Sub BeginCustomSummary(ByVal summarySettings As SummarySettings, ByVal rows As RowsCollection) Implements ICustomSummaryCalculator.BeginCustomSummary

          ' Begins the summary for the SummarySettings object passed in. Implementation of 
          ' this method should reset any state variables used for calculating the summary.
          Me.totals = 0

      End Sub

      Private Sub AggregateCustomSummary(ByVal summarySettings As SummarySettings, ByVal row As UltraGridRow) Implements ICustomSummaryCalculator.AggregateCustomSummary

          ' Here is where we process each row that gets passed in.

          Dim unitPrice As Object = row.GetCellValue(summarySettings.SourceColumn.Band.Columns("Unit Price"))
          Dim quantity As Object = row.GetCellValue(summarySettings.SourceColumn.Band.Columns("Quantity"))

          ' Handle null values
          If unitPrice Is DBNull.Value Or quantity Is DBNull.Value Then
              Return
          End If

          ' Convert to decimal.
          Try
              Dim nUnitPrice As Decimal = Convert.ToDecimal(unitPrice)
              Dim nQuantity As Decimal = Convert.ToDecimal(quantity)

              Me.totals += nQuantity * nUnitPrice
          Catch e As Exception
              ' This should not happen if the columns are numeric.
              Debug.Assert(False, "Exception thrown while trying to convert cell's value to decimal !")
          End Try

      End Sub

      Private Function EndCustomSummary(ByVal summarySettings As SummarySettings, ByVal rows As RowsCollection) Implements ICustomSummaryCalculator.EndCustomSummary

          ' This gets called when the every row has been processed so here is where we
          ' would return the calculated summary value.
          Return Me.totals

      End Function
  End Class

  Private Sub Button12_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button12.Click

      Dim band As UltraGridBand = Me.ultraGrid1.DisplayLayout.Bands(2)

      ' Add the OrderTotals custom summary.
      Dim summary As SummarySettings = band.Summaries.Add("OrderTotals", SummaryType.Custom, _
          New OrderTotalsSummary(), band.Columns("Unit Price"), SummaryPosition.Left, Nothing)

      ' Set the format with which to format the calculated summary when displaying
      ' in the summary footer.
      summary.DisplayFormat = "Sales Total = {0:######.00}"

      ' Set the horizontal text align to right so that the text summary text is aligned
      ' right in the summary element.
      summary.Appearance.TextHAlign = HAlign.Right

      ' Set the summary position to Left so that it shows up on the left of the
      ' summary footer area.
      summary.SummaryPosition = SummaryPosition.Right

      ' Set the appearance of the summary.
      summary.Appearance.FontData.Bold = DefaultableBoolean.True
      summary.Appearance.ForeColor = Color.Maroon
      summary.Appearance.BackColor = Color.LightGray

      ' Set the text that shows up in the caption of the summary footer.
      band.SummaryFooterCaption = "Total Sales for Order (OrderID)"

      ' Set the appearance of the summary footer area.
      Me.ultraGrid1.DisplayLayout.Override.SummaryFooterAppearance.FontData.Bold = DefaultableBoolean.True
      Me.ultraGrid1.DisplayLayout.Override.SummaryFooterAppearance.BackColor = Color.White
      Me.ultraGrid1.DisplayLayout.Override.SummaryFooterAppearance.ForeColor = Color.Black

      ' Set the appearance for the caption on top of the summary area.
      Me.ultraGrid1.DisplayLayout.Override.SummaryFooterCaptionVisible = DefaultableBoolean.True
      Me.ultraGrid1.DisplayLayout.Override.SummaryFooterCaptionAppearance.BackColor = Color.DarkBlue
      Me.ultraGrid1.DisplayLayout.Override.SummaryFooterCaptionAppearance.ForeColor = Color.LightYellow

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

// A class that calculates the totals for orders.
private class OrderTotalsSummary : ICustomSummaryCalculator 
{
	private decimal totals = 0;

	internal OrderTotalsSummary( )
	{
	}

	public void BeginCustomSummary( SummarySettings summarySettings, RowsCollection rows )
	{

		// Begins the summary for the SummarySettings object passed in. Implementation of 
		// this method should reset any state variables used for calculating the summary.
		this.totals = 0;

	}

	public void AggregateCustomSummary( SummarySettings summarySettings, UltraGridRow row )
	{

		// Here is where we process each row that gets passed in.

		object unitPrice = row.GetCellValue( summarySettings.SourceColumn.Band.Columns["Unit Price"] );
		object quantity = row.GetCellValue( summarySettings.SourceColumn.Band.Columns["Quantity"] );

		// Handle null values
		if ( unitPrice is DBNull || quantity is DBNull )
		{
			return;
		}

		// Convert to decimal.
		try
		{
			decimal nUnitPrice = Convert.ToDecimal( unitPrice );
			decimal nQuantity = Convert.ToDecimal( quantity );

			this.totals += nQuantity * nUnitPrice;
		}
		catch ( Exception )
		{
			// This should not happen if the columns are numeric.
			Debug.Assert( false, "Exception thrown while trying to convert cell's value to decimal !" );
		}

	}

	
	public object EndCustomSummary( SummarySettings summarySettings, RowsCollection rows )		
	{

		// This gets called when the every row has been processed so here is where we
		// would return the calculated summary value.
		return this.totals;

	}
}

private void button12_Click(object sender, System.EventArgs e)
{

	UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[2];

	// Add the OrderTotals custom summary.
	SummarySettings summary = band.Summaries.Add( 
		"OrderTotals",					// Give an identifier (key) for this summary
		SummaryType.Custom,				// Summary type is custom
		new OrderTotalsSummary( ),		// Our custom summary calculator
		band.Columns["Unit Price"],		// Column being summarized. Just use Unit Price column.
		SummaryPosition.Left,			// Position the summary on the left of summary footer
		null							// Since SummaryPosition is Left, pass in null
		);
	
	// Set the format with which to format the calculated summary when displaying
	// in the summary footer.
	summary.DisplayFormat = "Sales Total = {0:######.00}";

	// Set the horizontal text align to right so that the text summary text is aligned
	// right in the summary element.
	summary.Appearance.TextHAlign = HAlign.Right;

	// Set the summary position to Left so that it shows up on the left of the
	// summary footer area.
	summary.SummaryPosition = SummaryPosition.Right;

	// Set the appearance of the summary.
	summary.Appearance.FontData.Bold = DefaultableBoolean.True;
	summary.Appearance.ForeColor = Color.Maroon;
	summary.Appearance.BackColor = Color.LightGray;

	// Set the text that shows up in the caption of the summary footer.
	band.SummaryFooterCaption = "Total Sales for Order [OrderID]";

	// Set the appearance of the summary footer area.
	this.ultraGrid1.DisplayLayout.Override.SummaryFooterAppearance.FontData.Bold = DefaultableBoolean.True;
	this.ultraGrid1.DisplayLayout.Override.SummaryFooterAppearance.BackColor = Color.White;
	this.ultraGrid1.DisplayLayout.Override.SummaryFooterAppearance.ForeColor = Color.Black;
	
	// Set the appearance for the caption on top of the summary area.
	this.ultraGrid1.DisplayLayout.Override.SummaryFooterCaptionVisible = DefaultableBoolean.True;
	this.ultraGrid1.DisplayLayout.Override.SummaryFooterCaptionAppearance.BackColor = Color.DarkBlue;
	this.ultraGrid1.DisplayLayout.Override.SummaryFooterCaptionAppearance.ForeColor = Color.LightYellow;

}
参照