The Cross Tab Report Sample consists of a StartForm with an ActiveReports Viewer control and a ProductWeeklySales report.
The Viewer control has its Dock property set to Fill. This ensures that the viewer resizes along with the form at run time. Right-click the form and select View Code to see the code used to run the report and display it in the viewer.
This report features a number of accumulated values using summary function property settings and calculated in the code behind the report.
This section of the report features static controls including Labels, a Picture, a Line, and a Shape control with its BackColor property set to yellow. The report header prints only once, on the first page of the report, so it is a good place for a title, company information, and a logo.
The page header section also contains static Label controls that print at the top of each page and serve as column headers for the group header sections.
This group header section has its DataField property set to CategoryName. This setting, along with data sorted by the same field, produces a report grouped by category. The section contains one bound TextBox control to display the category name at the beginning of each group. The section's UnderlayNext property is set to True so that the category prints to the left of the top line of data instead of above it.
Although this group header contains no controls and is hidden using the Height and Visible properties, it still performs two important functions. First, its DataField property is set to ProductName, sorting the data inside each category by product, and second, its related group footer section displays the bulk of the data for the report.
The detail section of this report is hidden using the Height and Visible properties, but it does contain four bound fields whose values are used in the code behind the report.
ReportStart Event
Right-click the report and select View Code to see how this report, which does not have its data source set using the data source icon on the Detail band, gets its data. Private variables are created to hold values, and are set initially within the ReportStart event.
DataInitialize Event
The data source is set in the DataInitialize event, and then unbound fields are added to the report's Fields collection. For more information on unbound reporting, see Unbound Reporting.
FetchData Event
The FetchData event, which runs once for each row in your dataset, is where most of this report's logic is set. See the comments in the code to understand how data is calculated and passed to the report's Fields collection.
Detail Format Event
In the Detail Format event, the value from the hidden txtDetProduct text box is collected and passed to the _sProductName variable.
For more information on section events, see Section Events.
gfCategory Format Event
In the gfCategory Format event for the outer group footer section, the Value for the txtCatPQTDChange text box is calculated by subtracting the prior year's quarter-to-date sales figure from the current quarter-to-date sales figure.
The BackColor of the txtCatPQTDChange text box is set to Red if the value is negative.
gfProduct Format Event
In the gfProduct Format event for the inner group footer section, the product name collected from the Detail Format event is passed to the txtProduct text box. The Value for the txtPQTDChange text box is calculated by subtracting the prior year's quarter-to-date sales figure from the current quarter-to-date sales figure.
The BackColor of the txtPQTDChange text box is set to Red if the value is negative.
This group footer section displays the bulk of the data for the report in TextBox controls that have values passed in code, or are bound to fields from the report's Fields collection (see FetchData and DataInitialize events in the code) using the DataField property. The total units and sales for each product is summarized using the following properties:
This group footer section displays totals of the gfProduct data in TextBox controls that have values passed in code, or are bound to fields from the report's Fields collection (see FetchData and DataInitialize events in the code) using the DataField property. The total units and sales for each category is summarized using the following properties:
This section is not used, so it is hidden using the Height and Visible properties. Otherwise, it would print at the bottom of each page. The section cannot be deleted, because its related PageHeader section is in use.
This section is not used, so it is hidden using the Height and Visible properties. Otherwise, it would print once at the end of the report. The section cannot be deleted, because its related ReportHeader section is in use.