Glossary Item Box
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.
To add an ActiveReport to your project
To connect the report to a data source
To add controls to the report
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 |
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 |
To write the code in Visual Basic
To write the code in C#
The following example shows what the code for the method looks like.
'Visual Basic Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ Detail.Format If Me.txtReorderLevel.Value=0 And Me.txtDiscontinued.Value = False Then Me.Detail.Visible = True Me.txtDiscontinued.Text = "" Me.txtReorderLevel.Text = "Need to Reorder" Me.txtReorderLevel.ForeColor = System.Drawing.Color.DarkRed Else Me.Detail.Visible = False End If End Sub
//C# int m_dis; private void Detail_Format(object sender, System.EventArgs eArgs) { m_dis = Int32.Parse(txtReorderLevel.Text); if((short)txtReorderLevel.Value == 0 && m_dis == 0) { this.Detail.Visible = true; this.txtDiscontinued.Text = ""; this.txtReorderLevel.Text = "Need to Reorder"; this.txtReorderLevel.ForeColor = System.Drawing.Color.DarkRed; } else { this.Detail.Visible = false; } }
To view the report
See Also |
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.