ActiveReports for .NET 3 Online Help Request technical support
Group on Unbound Fields
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Advanced > Unbound Reports > Group on Unbound Fields

Glossary Item Box

ActiveReports allows you to set up grouping in unbound reports. When setting up grouping, the group header's DataField property is used to retrieve the grouping data from the database in the same manner as a textbox's DataField property.

This walkthrough illustrates how to set up grouping in an unbound report.

This walkthrough is split into the following activities:

To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.

When you have completed this walkthrough, you will have a report that looks similar to the following.

Adding an ActiveReport to a Visual Studio project

To add an ActiveReport to your project

  1. Open a new project in Visual Studio.
  2. From the Project menu, select Add New Item.
  3. Select ActiveReports 3.0 File and rename the file rptUnboundGrp.
  4. Click Open.

Adding code to connect the report to a data source

To write the code in Visual Basic or C#

Adding controls to the report to contain data

To add controls to the report

  1. Add a GroupHeader/Footer section to your report by right-clicking the design surface of the report and selecting Insert > Group Header/Footer.
  2. Make the following changes to the group header:
    • Change the Name property to ghCategories
    • Change the BackColor property to Silver
    • Change the DataField property to CategoryID
    • Set the GroupKeepTogether property to All
    • Set the KeepTogether property to True
  3. Make the following change to the group footer:
    • Change the name to gfCategories
  4. Add the following controls to the GroupHeader section:

    Control DataField Name Text Miscellaneous Location
    TextBox CategoryName txtCategoryName Category Name ForeColor = Blue; BackColor = LightGray; Font size = 12 0.063, 0.063
    TextBox Description txtDescription Description Size = 6, 0.2 0.063, 0.375
    Label lblProductName Product Name Bold 0.063, 0.688
    Label lblUnitsInStock Units In Stock Bold 4.38, 0.688
  5. Add the following controls to the Detail section:
  6. Control DataField Name Text Location
    TextBox ProductName txtProductName Product Name 0.063, 0.063
    TextBox UnitsInStock txtUnitsInStock Units In Stock 4.75, 0.064
  7. Add the following controls to the GroupFooter section:

    Control DataField Name Text Miscellaneous Location
    Label lblTotalLabel Total Number of Beverages NA 2.6, 0
    TextBox ProductName txtTotalItems Total Items SummaryType = SubTotal
    SummaryFunc = Count
    SummaryRunning = Group
    SummaryGroup = ghCategories
    4.75, 0
    Line Line1 LineWeight = 3 X1 = 1.875 
    X2 = 6.44
    Y1 = 0
    Y2 = 0

Using the DataInitialize event to add fields

The Fields collection should never be accessed outside the DataInitialize and FetchData events.

To write the code in Visual Basic

Using the FetchData event to populate the report fields

To write the code in Visual Basic

To write the code in C#

Adding code to close the connection to the data source

To write the code in Visual Basic

To write the code in C#

Viewing the report

To view the report

  1. Add the ActiveReports viewer control to a Windows Form.
  2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports Windows Form Viewer for help.
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer. When previewing reports that have SQL statements generated at run time, a Save File As dialog will prompt you to save your queries in the project folder.

See Also

©2009. All Rights Reserved.