To add a new group

Parent Previous Next

 

Report Application Server .NET SDK Developer Guide

To add a new group


 







New groups are added to a report with the CrystalDecisions.ReportAppServer.Controllers.GroupController class. A group is defined by a field, however, not all fields can be grouped on. The CanGroupOn method of the GroupController class checks whether the field can be grouped on.

The order in which the groups appear in the Groups collection is important as it represents how the data is grouped in the report. The first group in the collection is the outermost group in the report; similarly, the last group in the collection is the innermost group in the report. When a group is removed, the indexes are re-organized so that the collection is still indexed from zero.

NoteNote

When a new group is added to a report, a new sorting definition is also added. This sorting definition will sort the records according to the group's condition field and group options. However, adding a group does not physically add the field to the group header or footer sections of the report. If you want the field name visibily rendered for the new group, you must programmatically add it to the appropriate section using the ResultFieldController class.

  1. Retrieve the DataDefController object.

Visual Basic

Dim dataDefController As DataDefController = rcd.DataDefController

C#

DataDefController dataDefController = rcd.DataDefController;

  1. Find the a field to group on.

The DataDefinition.ResultFields property returns all fields that have been added to the report design. This example assumes that the report design contains a Country field called from a table called Customer.

Visual Basic

Dim resultFields As Fields = dataDefController.DataDefinition.ResultFields
Dim groupField As Field = DirectCast(resultFields.FindField("{Customer.Country}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglishUS), Field)

C#

Fields resultFields = dataDefController.DataDefinition.ResultFields;
Field groupField = (Field)resultFields.FindField("{Customer.Country}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglishUS);

  1. Retrieve the GroupController object.

Visual Basic

Dim groupController As GroupController = dataDefController.GroupController

C#

GroupController groupController = dataDefController.GroupController;

  1. Create a new Group object and set the field to group on with the ConditionField property.

Visual Basic

Dim newGroup As CrystalDecisions.ReportAppServer.DataDefModel.Group = New GroupClass()
newGroup.ConditionField = groupField

C#

Group newGroup = new GroupClass();
newGroup.ConditionField = groupField;

  1. Call the Add method of the GroupController class to add the new group to the report based on the chosen field.

The first parameter of the Add method specifies the location of the new group relative to any existing groups in the report. A value of -1 indicates that the new group should become the innermost group in the report.

Visual Basic

groupController.Add(-1, newGroup)

C#

groupController.Add(-1, newGroup);

The following code adds a new group to a report based on the field Customer.Country. This example checks whether the selected field is a valid field to group on before attempting to create the group.

Visual Basic

Private Sub AddGroup(ByVal rcd As ISCDReportClientDocument)
 Dim dataDefController As DataDefController = rcd.DataDefController
 
 Dim resultFields As Fields = dataDefController.DataDefinition.ResultFields
 Dim groupField As Field = DirectCast(resultFields.FindField("{Customer.Country}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglishUS), Field)
 Dim groupController As GroupController = dataDefController.GroupController
 If groupController.CanGroupOn(groupField) Then
  Dim newGroup As Group = New GroupClass()
  newGroup.ConditionField = groupField
  groupController.Add(-1, newGroup)
 End If
End Sub

C#

private void AddGroup(ISCDReportClientDocument rcd)
{
 DataDefController dataDefController = rcd.DataDefController;
 
 Fields resultFields = dataDefController.DataDefinition.ResultFields;
 Field groupField = (Field)resultFields.FindField("{Customer.Country}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglishUS);
 GroupController groupController = dataDefController.GroupController;
 if (groupController.CanGroupOn(groupField))
 {
  Group newGroup = new GroupClass();
  newGroup.ConditionField = groupField;
  groupController.Add(-1, newGroup);  
 }
}

This list includes the namespaces used by the sample code:

© 2021 SAP AG. All rights reserved.

http://www.sap.com/sapbusinessobjects/

Support services

http://service.sap.com/bosap-support/

Created with the Personal Edition of HelpNDoc: Easily create Help documents