Showing or Hiding a Field Depending on a Value
Instead of changing the field format to highlight its contents, you could set another field's Visible property to True or False to create special effects. For example, if you created a new field called "BoxCtl" and formatted it to look like a bold rectangle around the product name, then you could change the script as follows:
If UnitsInStock < ReorderLevel Then
BoxCtl.Visible = True
Else
BoxCtl.Visible = False
End If
To highlight products that are below the reorder level using code:
To highlight products that are below the reorder level by displaying a box, use an event script that looks like this:
Dim script As String = _
"If UnitsInStock < ReorderLevel Then" & vbCrLf & _
" BoxCtl.Visible = True" & vbCrLf & _
"Else" & vbCrLf & _
" BoxCtl.Visible = False" & vbCrLf & _
"End If"
c1r.Sections.Detail.OnPrint = script
• C#
string script =
"if (UnitsInStock < ReorderLevel) then\r\n" +
"BoxCtl.Visible = true\r\n" +
"else\r\n" +
"BoxCtl.Visible = false\r\n" +
"end if\r\n";
c1r.Sections.Detail.OnPrint = script;
The code builds a string containing the VBScript event handler, and then assigns it to the section's OnPrint property.
To highlight products that are below the reorder level using C1ReportDesigner:
Alternatively, instead of writing the code, you can use the C1ReportDesigner application to type the following script code directly into the VBScript Editor of the Detail section's OnPrint property. Complete the following steps:
1. Select Detail from the Properties window drop-down list in the Designer. This reveals the section's available properties.
2. Click the empty box next to the OnPrint property, then click the drop-down arrow, and select Script Editor from the list.
3. In the VBScript Editor, simply type the following script in the window:
If UnitsInStock < ReorderLevel Then
BoxCtl.Visible = True
Else
BoxCtl.Visible = False
End If
The following screen capture shows a section of the report with the special effects:
|