Share via


Visual Basic Concepts

Grouping Information in the Data Report

Information that is grouped can give the user a different perspective on data. Working in tandem with the Data Environment designer, the Data Report designer gives you the ability to group data according to any field in a table. The figure below shows a data report grouped by countries.

Data Report Grouped By Country

Grouping by Command Field

The grouping field provided by the data environment's Command object differs from the grouping already achieved by creating group headers and footers. Instead of using the table of a database as the basis for grouping, the Grouping feature of the Data Environment designer allows you to select a particular field in the table as the grouping field without having to create a new Command object.

The steps to adding a grouping field include:

  1. Creating a group field in the Data Environment designer.

  2. Adding a Group Header/Footer to the Data Report designer to correspond to the new command.

  3. Resetting the DataMember property of the data report to the new Grouping Command object created in the data environment.

  4. Dragging the group field from the data environment to the data report.

Note   This topic is part of a series that walks you through creating a sample data report. It begins with the topic, Creating a Simple Data Report.

To add a grouping field to the Data Report designer

  1. In the Data Environment designer, right click the Customers Command object. Click Properties to show the Customers Properties dialog box.

  2. Click the Grouping tab.

  3. Click Group Command Object.

  4. In the Fields in Command box, double-click Country. Click OK to close the dialog box.

    Notice that the Customers Command object has been renamed as Customers Grouped using Customers_Grouping, and that two new folders have been created for the fields. The first, Summary fields in Customer_Grouping contains the field(s) that the subordinate fields will be grouped by. The subordinate fields are contained in the second folder, Detail Fields in Customer_Grouping.

  5. Right-click the Data Report designer, and then click Insert Group Header/Footer.

  6. Click the up arrow three times to insert the group header at the outermost edge of the header/footer pairs. Click OK to close the dialog box.

  7. On the Data Report designer, click the new Group Header to select it, and change its name from Section1 to Customers_Grouping_Header in the Properties window. Click the new Group Footer to select it, and change its name to Customers_Grouping_Footer.

  8. Click the Data Report designer's title bar to select the entire data report. On the Properties window, click DataMember and change the property from Customers to Customers_Grouping.

    When the grouping field was added to the data environment, the equivalent of a new Command object was also added to the data report. That virtual Command object is displayed in the drop-down list of data members as Customers_Grouping.

  9. In the Data Environment designer, open Summary Fields in Customers_Grouping. Drag the Country field into the new section on the Data Report designer.

  10. Delete the Label control that accompanies the Country****field. Place the new field at the leftmost edge of the designer, which should now resemble the figure below:

  11. Save and run the project.

Step by Step

This topic is part of a series that walks you through creating a sample data report.

To See
Go to the next step Adding an Aggregate Field to the Data Report
Start from the beginning Creating a Simple Data Report