Skip to main content Skip to footer

How To : Toggle Visibility of Subreports Using C1ReportDesigner

A SubReport is a report that is inserted in another report. Subreports are useful when you want to combine several reports into one. In C1Report, creating a Subreport is very simple. To know, how to create Subreports, you can read this Documentation link. Now, there might be certain scenarios where you would like to customize the way how the Subreports appear in the final output. In this Blog, we are covering the following two scenarios.

*** Display Subreports conditionally

  • Vary the number of Subreports to be displayed**

This can be done only using VBScript editor of C1ReportDesigner. We need to add the desired script-code into the OnPrint property of Detail section of the report. In our blog implementation, we will handle the custom display of Subreports on the basis of the field value in the Main Report.

Case1 : Display different SubReports

This implementation toggles the visibility of the SubReports on the basis of a field value in the Main report. That is, if there are multiple Subreports, only the related Subreport is displayed and rest of the reports are hidden. To do this, follow the mentioned steps :

  1. Add the different subreports in the detail section one over the other in C1ReportDesigner. Since, in this case only one field will be visible at a time, the fields are added one over the other to avoid any blank spaces while rendering of the report.
  2. Set the Visible property of each of them to False.
  3. Now check the last fetched value in the Detail Section and toggle the visibility of the subreports on it’s basis. Add the following code in the VBScript Editor :
    str=VehicleName  
    Field2.Text=str  
    If str="Car" then  
        CarSubReport.Visible= True  
        BikeSubReport.Visible= False  
        BoatSubReport.Visible= False  
    Elseif str="Boat" then  
        BoatSubReport.Visible= True  
        CarSubReport.Visible= False  
        BikeSubReport.Visible= False  
    Elseif str="Bike" then  
        BikeSubReport.Visible= True  
        CarSubReport.Visible= False  
        BoatSubReport.Visible= False  
    Endif
    

Case2 : Display different number of SubReports

In case, you want to display different number of SubReports on the main report, follow the under mentioned steps :

  1. Add multiple subreports vertically, one below the other in the Detail Section of C1ReportDesigner. Set the height of each to "1". Since, more than one Subreport might be visible at a time, the fields are added one below the other to avoid any overlapping of text in the rendered report. Also, note that the height of each subreport is set to a minimum value of "1". This is done to ensure that no blank space is present in the rendered report, if the visibility of that subreport is set to false.
  2. Set the Visible property of each of them to False and CanGrow property to True.
  3. Now check the last fetched value in the Detail section and toggle the visibility of the subreports on it’s basis. Add the following code in the VBScript Editor :
    str=Number  
     If str="1" then  
         CarSubReport.Visible= True  
         BikeSubReport.Visible= False  
         BoatSubReport.Visible= False  
     Elseif str="2" then  
         CarSubReport.Visible= True  
         BikeSubReport.Visible= True  
         BoatSubReport.Visible= False  
     Elseif str="3" then  
         CarSubReport.Visible= True  
         BikeSubReport.Visible= True  
         BoatSubReport.Visible= True  
     Endif
    

Refer to the attached report xml for the complete implementation. Download XML

MESCIUS inc.

comments powered by Disqus