Glossary Item Box

Samples | Walkthroughs

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

Walkthrough: Conditional Show-Hide Detail

ActiveReports allows you to hide or show information from the data source in the Detail section of your report based on conditions in your data. This can be achieved by setting properties of the section in the Format event based on certain conditions.

This walkthrough illustrates how to create a report based on conditions that will show specific data from your data source at run time.

This walkthrough is split up 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 rptCondSH.
  4. Click Open.

Connecting the report to a data source

To connect the report to a data source

  1. Click on the yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
  2. Click on Build...
  3. Select Microsoft Jet 4.0 OLE DB Provider and click Next >>
  4. Click on the ellipsis to browse for the access path to NWind.mdb. Click Open once you have selected the appropriate access path.
  5. Click OK to continue.
  6. In the Query field, type "Select * from products ORDER BY productname".
  7. Click OK to return to the report design surface.

Adding controls to the report to contain data

To add controls to the report

  1. Add a PageHeader/Footer section to the report.
  2. Add the following controls to the PageHeader section:

    Control Name Text/Caption Location
    Label lblProductID Product ID 0, 0
    Label lblProductName Product Name 1.0625, 0
    Label lblReorderLevel Reorder Level 3.8125, 0
    Label lblInStock Units In Stock 2.5, 0

  3. Add the following controls to the Detail section:

    Control DataField Name Text/Caption Location
    TextBox ProductID txtProductID Product ID 0, 0
    TextBox ProductName txtProductName Product Name 1.0625, 0
    TextBox UnitsInStock txtUnitsInStock Units In Stock 2.510, 0
    TextBox ReorderLevel txtReorderLevel Reorder Level 3.833, 0
    TextBox Discontinued txtDiscontinued Discontinued 5.291, 0

Adding conditions in code to the format event

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

 

 


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