Glossary Item Box

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

Green Bar Reports

Green bar printouts can be created by alternating the shading or background color of the report's Detail section in the Format event.

This walkthrough illustrates how to create a green bar report.

The 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 finished this walkthrough, you will have a report that looks similar to the following.

Creating a new Visual Studio project

To create a new Visual Studio project

  1. Open Visual Studio.
  2. Click on File > New > Project.

  3. Select the project type and click on Windows Application.
  4. Change the name of your project and click OK.

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 rptGreenBar.
  4. Click Open.

Connecting the data source to a database

To connect the data source to a database

  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".
  7. Click OK to return to the report design surface.

Adding controls to contain data

To add controls to the report

  1. 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 0.9, 0
    TextBox UnitsInStock txtUnitsInStock Units in Stock 3.5, 0
    TextBox UnitsOnOrder txtUnitsOnOrder Units on Order 4.5, 0
    TextBox ReorderLevel txtReorderLevel Reorder Level 5.6, 0
  2. Add the following controls to the PageHeader section:
    Control Name Text/Caption Formatting Location
    Label lblTitle Reorder Sheet Font 14pt; Bold; Center 0, 0
    Label lblProductID Product ID Underline 0, 0.365
    Label lblProductName Product Name Underline 0.9, 0.365
    Label lblUnitsInStock Units in Stock Underline 3.5, 0.365
    Label lblUnitsOnOrder Units on Order Underline 4.5, 0.365
    Label lblReorderLevel Reorder Level Underline 5.6, 0.365

Adding code to the Detail_Format event to alternate colors

To add code to the the Detail_Format event

  1. Double-click in the Detail section to go to the Detail_Format event
  2. Add the following code to the event to alternate background colors.

    ' Visual Basic
    Dim I As Integer
    Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ Detail.Format
    If (I Mod 2) = 0 Then
    Detail.BackColor = System.Drawing.Color.DarkSeaGreen
    Else
    Detail.BackColor = System.Drawing.Color.Transparent
    End If I = I + 1
    End Sub

    //C#
    bool m_color;
    private void Detail_Format(object sender, System.EventArgs eArgs)
    {
    if(m_color)
    {
    m_color =false;
    this.Detail.BackColor = System.Drawing.Color.DarkSeaGreen;
    }
    else
    {
    this.Detail.BackColor = System.Drawing.Color.Transparent;
    m_color = true;
    }
    }

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.

 

 


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