ActiveReports 11
Category Selection
ActiveReports 11 > ActiveReports User Guide > Samples and Walkthroughs > Samples > Section Report > Layout > Category Selection

The CategorySelection sample demonstrates passing a SQL string into a report at run time. It consists of a CategorySelectForm and CategoryProducts report.

Sample Location

Visual Basic.NET

<User Folder>\Documents\GrapeCity Samples\ActiveReports 11\Section Reports\Layout\CategorySelection\VB.NET

C#

<User Folder>\Documents\GrapeCity Samples\ActiveReports 11\Section Reports\Layout\CategorySelection\C#

Run-Time Features

When you run this sample, a form containing a Viewer control and a ComboBox control within a panel is displayed. The Select a Product Category ComboBox at the top of the form allows the users to select the type of data they want to display in the Viewer control.

Note: To run this sample, you must have access to the Nwind.mdb. A copy is located at [User Documents folder]\GrapeCity Samples\ActiveReports 11\Data\NWIND.mdb. If you are unable to access the data files in the sample, create the Data folder and place all the data files to this folder, or change the reference path to the data files within the folder according to your environment.

Project Details

CategorySelectForm

The Viewer control fills most of the form, and a ComboBox at the top allows the user to select which data to send to the Viewer control.

To see how all of this works, right-click the form and select View Code.

  • The getCategories code populates the ComboBox with the category names.
  • The runCategoryReport code runs the report with a SQL string with the CategoryName passed in by the ComboBox selection.
  • The SelectIndexChanged event calls runCategoryReport and passes the CategoryName.

CategoryProducts

This report lists the products in the selected category, and summarizes the number of products.

ReportHeader section

This section cannot be deleted, because the related ReportFooter section is used and thus the Height property is set to 0.

PageHeader section

This section uses Label controls, Line controls and a TextBox. DataField property of  txtCategory TextBox is set to CategoryName. Two Line controls and three Label controls create the report title and the column headers for this report.

Detail section

This section contains two bound TextBox controls to display each product in the selected category along with its price. Although the form passes data to the report at run time, the report's data source is set for design time use. At design time, it is easier to drag bound fields onto the report from the Report Explorer than it is to create them and set their properties. The data source also allows you to preview the report while you are designing it.

PageFooter section

This section uses the ReportInfo control to display Page N of M. In the Properties window, you can select a way to display the page number and run date using the FormatString property.

ReportFooter section

This section contains a Label control and a bound TextBox. The TextBox has the SummaryType set to GrandTotal and DataField property set to ProductName to display the total number of products in the selected category.
See Also

How To