To modify a subreport with the SubreportClientDocument class

Parent Previous Next

 

Report Application Server .NET SDK Developer Guide

To modify a subreport with the SubreportClientDocument class


 







You can programmatically modify the structure of a subreport. This example shows how to modify the background color of the first field object in the subreport. The workflow for modifying a subreport is the same as for modifying a report. Use the main report's SubreportController class to retrieve an ISubreportClientDocument interface, and then use the standard controllers to modify the subreport.

  1. Get the SubreportController object from the main report.

Visual Basic

Dim subreportController As SubreportController = rcd.SubreportController

C#

SubreportController subreportController = rcd.SubreportController;

  1. Get the ISubreportClientDocument object using its alias (name).

Visual Basic

Dim subreportClientDocument As SubreportClientDocument = subreportController.GetSubreport(subreportName)

C#

SubreportClientDocument subreportClientDocument = subreportController.GetSubreport(subreportName);

  1. Get the ReportDefController object for the subreport.

Visual Basic

Dim subreportDefController As ReportDefController2 = subreportClientDocument.ReportDefController

C#

ReportDefController2 subreportDefController = subreportClientDocument.ReportDefController;

  1. Get the first field object in the subreport.

Visual Basic

Dim subreportObjectController As ReportObjectController = subreportDefController.ReportObjectController
Dim reportObjects As ReportObjects = subreportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindField)
Dim fieldObject As FieldObject = DirectCast(reportObjects(0), FieldObject)

C#

ReportObjectController subreportObjectController = subreportDefController.ReportObjectController;
ReportObjects reportObjects = subreportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindField);
FieldObject fieldObject = (FieldObject)reportObjects[0];

  1. Create a clone of the field object and modify its properties.

This example sets the background color of the field to java.awt.Color.YELLOW.

Visual Basic

Dim newObject As FieldObject = DirectCast(fieldObject.Clone(True), FieldObject)
newObject.Border.BackgroundColor = UInteger.Parse(ColorTranslator.ToOle(Color.Yellow).ToString())

C#

FieldObject newObject = (FieldObject)fieldObject.Clone(true);
newObject.Border.BackgroundColor = uint.Parse(ColorTranslator.ToOle(Color.Yellow).ToString());

  1. To modify the field object, call the modify method of the subreport's ReportObjectController object.

Visual Basic

subreportObjectController.Modify(fieldObject, newObject)

C#

subreportObjectController.Modify(fieldObject, newObject);

This sample sets the background colour to yellow for the first field object in the subreport.

Visual Basic

Private Sub ModifySubreportClientDocument(ByVal rcd As ISCDReportClientDocument, ByVal subreportName As String)
 Dim subreportController As SubreportController = rcd.SubreportController
 Dim subreportClientDocument As SubreportClientDocument = subreportController.GetSubreport(subreportName)
 Dim subreportDefController As ReportDefController2 = subreportClientDocument.ReportDefController
 Dim subreportObjectController As ReportObjectController = subreportDefController.ReportObjectController
 Dim reportObjects As ReportObjects = subreportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindField)
 Dim fieldObject As FieldObject = DirectCast(reportObjects(0), FieldObject)
 Dim newObject As FieldObject = DirectCast(fieldObject.Clone(True), FieldObject)
 newObject.Border.BackgroundColor = UInteger.Parse(ColorTranslator.ToOle(Color.Yellow).ToString())
 subreportObjectController.Modify(fieldObject, newObject)
End Sub

C#

private void ModifySubreportClientDocument(ISCDReportClientDocument rcd, string subreportName)
{
 SubreportController subreportController = rcd.SubreportController;
 SubreportClientDocument subreportClientDocument = subreportController.GetSubreport(subreportName);
 ReportDefController2 subreportDefController = subreportClientDocument.ReportDefController;
 ReportObjectController subreportObjectController = subreportDefController.ReportObjectController;
 ReportObjects reportObjects = subreportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindField);
 FieldObject fieldObject = (FieldObject)reportObjects[0];
 FieldObject newObject = (FieldObject)fieldObject.Clone(true);
 newObject.Border.BackgroundColor = uint.Parse(ColorTranslator.ToOle(Color.Yellow).ToString());
 subreportObjectController.Modify(fieldObject, newObject);
}

This list includes the namespaces used by the sample code:

© 2021 SAP AG. All rights reserved.

http://www.sap.com/sapbusinessobjects/

Support services

http://service.sap.com/bosap-support/

Created with the Personal Edition of HelpNDoc: Easily create Help documents