ActiveReports Developer 7
Conditionally Show or Hide Details
See Also Support Forum
ActiveReports Developer 7 > ActiveReports Developer Guide > How To > Section Report How To > Conditionally Show or Hide Details

Glossary Item Box

In a section layout, you can use conditions in the Format event to control the display of report's detail section at runtime.

These steps assume that you have already added a Section Report (code-based) template in a Visual Studio project and connected it to a data source. See Adding an ActiveReport to a Project and Bind Reports to a Data Source for further information.

Note: These steps use the Products table from the NWind database. By default, in ActiveReports Developer, the NWind.mdb file is located in the [User Documents folder]\ComponentOne Samples\ActiveReports Developer 7\Data\NWind.mdb.
  1. From the Report Explorer, drag and drop the following fields onto the detail section of the report and set their properties in the Properties Window.
    Field Name Properties
    ProductName Location: 0, 0.104 in
    Size: 2.667, 0.2 in
    Discontinued Location: 2.667, 0.104 in
    Size: 2.021, 0.2 in
    ReorderLevel Location: 4.688, 0.104 in
    Size: 1.812, 0.2 in
  2. Double-click the detail section of the report to create an event-handling method for the Format event.
  3. Add the following code to the handler to hide the details of a product which is discontinued.

    ShowTo write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Detail_Format event. Copy Code
    If Me.txtReorderLevel1.Value = 0 And Me.txtDiscontinued1.Value = False Then
       Me.Detail1.Visible = True
       Me.txtReorderLevel1.Text = "Need to Reorder"
       Me.txtReorderLevel1.ForeColor = System.Drawing.Color.DarkRed
    Else
       Me.Detail1.Visible = False
    End If

    ShowTo write the code in C#

    C# code. Paste INSIDE the detail_Format event. Copy Code
    if (int.Parse(txtReorderLevel1.Value.ToString()) == 0 && txtDiscontinued1.Text == "False")
    {
    this.detail1.Visible = true;
    this.txtReorderLevel1.Text = "Need to Reorder";
    this.txtReorderLevel1.ForeColor = System.Drawing.Color.DarkRed;
    }
    else
    {
    this.detail1.Visible = false;
    }
  4. In Form1 of the Visual Studio project, add a Viewer control and load the report you created above in it. See Using the Viewer for further details.
  5. Press F5 to debug and see a report with discontinued products hidden from view.

See Also

©2014. ComponentOne, a division of GrapeCity. All rights reserved.