Glossary Item Box

Samples | Walkthroughs | Grouping Data | SummaryFunc enumeration | GroupKeepTogether enumeration

See Also ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

Group on Unbound Fields

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

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 (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. Click on Project > Add New Item.
  3. Select ActiveReports 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

To write the code in C#

Adding code to close the connection to the DataReader

To write the code in Visual Basic

To write the code in C#

Adding controls to the report to contain data

To add controls to the report

  1. Add a GroupHeader/Footer section to your report (see Grouping Data for help).
  2. Make the following changes to the group header:
    • Change the name to ghCategories
    • 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/Caption Location
    TextBox CategoryName txtCategoryName Category Name 0.0625, 0.0625
    TextBox Description txtDescription Description 0.0625, 0.375
    Label (Empty string) lblProductName Product Name 0.0625, 0.6875
    Label (Empty string) lblUnitsInStock Units In Stock 4.75, 0.6875
  5. Add the following controls to the Detail section:

    Control DataField Name Text/Caption Location
    TextBox ProductName txtProductName Product Name 0.0625, 0.0625
    TextBox UnitsInStock txtUnitsInStock Units In Stock 4.75, 0.0625
  6. Add the following controls to the GroupFooter section:

    Control DataField Name Text/Caption Misc Details Location
    Label TotalLabel lblTotalLabel Total Label (Empty string) 1.875, 0
    TextBox ProductName txtTotalItems Total Items SummaryType = SubTotal

    SummaryFunc = Count

    SummaryRunning = Group

    SummaryGroup = ghCategories

    5, 0
    Line (Empty string) Line1 (Empty string) LineWeight = 3 X1 = 1.875

    Y1 = 0

    X2 = 6.4375

    Y2 = 0

Using the DataInitialize event to add fields

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

To write the code in Visual Basic

To write the code in C#

Using the FetchData event to populate the report fields

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 WinForm Viewer for help.

Samples | Walkthroughs | Grouping Data | SummaryFunc enumeration | GroupKeepTogether enumeration

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.