How Do I Use Grouping With ActiveReports for .NET?


06-19-2003, 12:00 PM
With ActiveReports for .NET, reports can be grouped by setting the DataField property of your GroupHeaders.

Note: ActiveReports will not group your data, so if you have not sorted your data prior to passing it to the report, you will get strange results.

This walkthrough is split up into the following activities:

To add the viewer to a WinForm:

  1. Create a new WinForms project.
  2. From your toolbox, add an ActiveReports "Viewer" to the form.
  3. In the properties grid, choose the Dock property, and select "Fill".

To add an ActiveReport:

  1. Select "Add New Item..." from the Project menu.
  2. Scroll down and choose "ActiveReports File"

Note: If there is no ActiveReports file listed, you are probably trying to run an older build of ActiveReports for .NET in Visual Studio.NET 2003. If this is the case, you can download the latest hot fix here.

To connect the report to the nwind.mdb:

  1. Click the yellow icon on the Detail bar of the report.
  2. Click the "Build..." button.
  3. Double-click "Microsoft Jet 4.0 OLE DB Provider".
  4. Click the ellipsis button next to "Select or enter a database name:", choose nwind.mdb, and click OK.
  5. In the Query box, type the following: SELECT * FROM Customers ORDER BY Country
  6. Click OK.

To add groups to the report:

  1. Right-click anywhere on the report.
  2. Choose Insert > > Group Header/Footer.
  3. In the properties grid, drop down the list of fields in the DataField property of the GroupHeader, and choose Country.
  4. Drag the Country field into the GroupHeader from the Fields list, and a few other fields into the Detail section.

To link the report to the viewer:

  1. Go to the Form Load event of Form1.
  2. Add the following code to that event:

Dim rpt As New ActiveReport1() rpt.Run() Me.Viewer1.Document = rpt.Document

You should now be able to run your project, and see a report grouped by country.