Group Data by a Custom Field

  • 2 minutes to read

This tutorial illustrates how to group a report against a custom criteria at design time within Visual Studio. In the report created in this example, products are grouped by a calculated field that returns the first letter of the product name.

How to - ImplementCustomGrouping_4

Do the following to group a report by a custom field:

  1. To create a table report in this tutorial, start with a report that is bound to the “Products” table of the sample Northwind database (the nwind.mdb file included in the XtraReports installation). To learn more about binding a report to a data source, see Provide Data to Reports.
  2. To create a calculated field, switch to the Field List, right-click any item inside the nwindDataSet1 and select Add Calculated Field in the menu that is invoked.

    HowTo - CreateCalcField_0

    As a result, the CalculatedField.DataMember property is automatically set to the “Products” table of the project’s data set, which means that the calculated field can access data fields from this table.

  3. Next, select the created field, set its CalculatedField.Name property to Initial (the field’s CalculatedField.DisplayName will be automatically set to the same value) and set the CalculatedField.FieldType property to String.

    How to - ImplementCustomGrouping_0

    Then click the ellipsis button for the calculated field’s CalculatedField.Expression property, to invoke the Expression Editor.

  4. Define the following expression in the editor that is invoked: Substring([ProductName], 0 ,1 ). This will extract the initial letter from the ProductName data field.

    How to - ImplementCustomGrouping_1

    To close the editor and save the changes, click OK.

  5. To quickly create a Group Header band associated with the calculated field, use the Group and Sort panel.

    If the panel is not displayed, you can make it visible by checking the corresponding item in the XtraReports Menu.


    To create a grouping criteria, click Add a Group and select the calculated field from the invoked drop-down menu.

    How to - ImplementCustomGrouping_3

    You can also use this panel to specify whether or not the corresponding Group Footer band should be visible. The Sort Order drop-down list allows you to define the sort order within the group (ascending or descending) or disable sorting in grouped data.

  6. Next, switch to the Field List and drop the required data fields onto the report’s Detail band, and the Initial calculated field onto the Group Header area.

    How to - ImplementCustomGrouping_2

See Also