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. |
- 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 inDiscontinued Location: 2.667, 0.104 in
Size: 2.021, 0.2 inReorderLevel Location: 4.688, 0.104 in
Size: 1.812, 0.2 in - Double-click the detail section of the report to create an event-handling method for the Format event.
- 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 IfC# 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;
} - 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.
- Press F5 to debug and see a report with discontinued products hidden from view.