Version

Performing External Summary Calculations

Topic Overview

Purpose

This topic explains, with code examples, the most common tasks related to performing external summary calculations in the UltraGrid™ control.

Required Background

The following table lists the topics required as a prerequisite to understanding this topic.

Topic Purpose

This topic demonstrates loading of data on demand with the CellDataRequested event.

External Summary Calculations Overview

External summary calculations tasks chart

The following table lists the configurable aspects of the WinGrid control. Additional details are available after the summary table.

External calculation task Details Property/Enum/Method

Enabling external summary calculations

The summary type is set to External on the summaries collection for the specific Band.

Implementing external summary calculations

The ExternalSummaryValueRequested event exposes a SetExternalSummaryValue method that is used to set the summary value directly or externally.

Implementing external summary calculations on summary calculator

Set the UseExternalSummaryCalculator property to true.

Enabling External Summary Calculations

Overview

To enable external summary calculations, the summary type must be set to External on the summaries collection for the specific Band. With the external summary calculation functionality, the UltraGrid control’s summary calculation logic is bypassed that ends up iterating the rows collection to calculate the summary value and will also avoid requesting all of the data to be loaded. This provides the ability to add summaries to the UltraGrid control as well as load data on demand.

Property settings

The following table maps the desired configuration to property setting.

In order to: Use this Enum: And set it to:

Enable external summary calculation

External

Code Example

The following sample code sets the Summary type to External using the Add method on the Summaries collection.

In Visual Basic:

Dim band As UltraGridBand = Me.ultraGrid1.DisplayLayout.Bands(0)
' Add a summary of type External.
Dim summary As SummarySettings = band.Summaries.Add(SummaryType.External, band.Columns("ID"))

In C#:

UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0];
// Add a summary of type External.
SummarySettings summary = band.Summaries.Add( SummaryType.External, band.Columns["ID"] );

Implementing External Summary Calculations – Conceptual Overview

Overview

When the summary type is set to External, the ExternalSummaryValueRequested event is fired. This event exposes a SetExternalSummaryValue method that is used to set the summary value directly or externally.

Property settings

The following table maps the desired configuration to property setting.

In order to: Use this property: And set it to:

Assign an external summary value

The desired value

Implementing External Summary Calculations – Code Example

Description

The code example that follows demonstrates the UltraGrid control displaying the external summary value as a result of the following setting:

Property Value

90

Preview

Following is preview of the external summary value being displayed as a result of implementing the sample code.

Performing External Summary Calculations  1 1.png

Code

The following sample code sets the Summary externally or directly within the ExternalSummaryCalculated event.

In Visual Basic:

Private Sub ultraGrid1_ExternalSummaryValueRequested(sender As Object, e As ExternalSummaryValueEventArgs)
e.SummaryValue.SetExternalSummaryValue("90")
End Sub

In C#:

private void ultraGrid1_ExternalSummaryValueRequested(object sender, ExternalSummaryValueEventArgs e)
{
         e.SummaryValue.SetExternalSummaryValue("90");
}

Implementing External Summary Calculations on the Summary Calculator – Conceptual Overview

Overview

Summaries (Average, Count, Maximum, Minimum and Sum) on the Summary Calculator can also be calculated externally. This is achieved by setting the UseExternalSummaryCalculator property to true. This property is available on UltraGrid.Override as well as on a particular Band.Override. When this property is set to True, UltraGrid will cease summary calculations and fire the ExternalSummaryValueRequested event, requesting the value to place in the summary.

Property settings

The following table maps the desired configuration to property setting.

In order to: Use this property: And set it to:

Enable external summary calculation on summary calculator

DefaultableBoolean.True

Assign an external summary value to the Count summary type

The desired value

Assign an external summary value to the Maximum summary type

The desired value

Implementing External Summary Calculations on the Summary Calculator – Code Example

Description

The ode example that follows demonstrates the UltraGrid control displaying external summary value on the Summary Calculator as a result of the following setting:

Property Value

SetExternalSummaryValue

5

SetExternalSummaryValue

100

Preview

The following snapshot demonstrates the effect of the settings listed in the Example text block: the UltraGrid displaying external Summary value on the Summary Calculator for a child band.

Performing External Summary Calculations  1 2.png

Code

The following sample code sets the Summary Calculator to External. The UseExternalSummaryCalculator property is set to True. UltraGrid displays external summary value on Summary Calculator for child band. The summary value is set within the ExternalSummaryValueRequested event.

In Visual Basic:

' Allow summary calculator to calculate summaries externally for the entire Grid
' this.ultraGrid1.DisplayLayout.Override.UseExternalSummaryCalculator = DefaultableBoolean.True;
' Allows Summary Calculator to calculate summaries externally for a specific band(Bands[1]).
' UltraGrid summary calcuation is stopped and                                    'ultraGrid1_ExternalSummaryValueRequested event is  fired.
Me.ultraGrid1.DisplayLayout.Bands(1).Override.UseExternalSummaryCalculator = Infragistics.Win.DefaultableBoolean.True
Private Sub ultraGrid1_ExternalSummaryValueRequested(sender As Object, e As ExternalSummaryValueEventArgs)
      Select Case e.SummaryValue.SummarySettings.SummaryType.ToString()
            Case "Count"
                  e.SummaryValue.SetExternalSummaryValue(5)
                  Exit Select
            Case "Maximum"
                  e.SummaryValue.SetExternalSummaryValue(100)
                  Exit Select
      End Select
End Sub

In C#:

// Allow summary calculator to calculate summaries externally for the entire // Grid
// this.ultraGrid1.DisplayLayout.Override.UseExternalSummaryCalculator =
// DefaultableBoolean.True;
// Allows Summary Calculator to calculate summaries externally for a specific
// band(Bands[1]).
// UltraGrid summary calcuation is stopped and
// ultraGrid1_ExternalSummaryValueRequested event is fired.
this.ultraGrid1.DisplayLayout.Bands[1].Override.UseExternalSummaryCalculator =
Infragistics.Win.DefaultableBoolean.True;
private void ultraGrid1_ExternalSummaryValueRequested(object sender, ExternalSummaryValueEventArgs e)
{
        switch (e.SummaryValue.SummarySettings.SummaryType.ToString())
        {
            case "Count":
            e.SummaryValue.SetExternalSummaryValue(5);
            break;
            case "Maximum":
            e.SummaryValue.SetExternalSummaryValue(100);
            break;
        }
}

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic illustrates how to display the column summaries in a position other than the bottom of the column

This topic shows how to fix the summaries so they don’t scroll.