ActiveReports 14 .NET Edition
ActiveReports 14 User Guide / How To / Section Report How To / Common Tasks / Conditionally Show or Hide Details
In This Topic
    Conditionally Show or Hide Details
    In This Topic

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

    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 Quick Start and Bind Reports to a Data Source for further information.

    Note: These steps use the Products table from the NWind database. The NWIND.mdb file can be downloaded from GitHub: ..\Samples14\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.

      To 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

      To 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 Windows Forms Viewer for further details.
    5. Press F5 to debug and see a report with discontinued products hidden from view.

      A report hiding details in the Viewer

      A report hiding details in the Viewer



    See Also