ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1Report > Using Event Properties > Hiding a Section if There is No Data for It

Hiding a Section if There is No Data for It

You can change a report field's format based on its data by specifying an expression for the Detail section's OnFormat property.

For example, your Detail section has fields with an image control and when there is no data for that record's image you want to hide the record. To hide the Detail section when there is no data, in this case a record's image, add the following script to the Detail section's OnFormat property:

If isnull(PictureFieldName) Then
Detail.Visible = False
Else
Detail.Visible = True
End If

To hide a section if there is no data for it using code:

To hide a section if there is no data, in this case a record's image, for it, use an event script that looks like this:

      Visual Basic

c1r.Sections.Detail.OnFormat = "Detail.Visible = not

isnull(PictureFieldName)"

      C#

c1r.Sections.Detail.OnFormat = "Detail.Visible = not

isnull(PictureFieldName)";

To hide a section if there is no data for it 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 OnFormat 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 OnFormat 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 isnull(PictureFieldName) Then
Detail.Visible = False
Else
Detail.Visible = True
End If

      Or you could use the more concise version:

Detail.Visible = not isnull(PictureFieldName)


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.