cancel
Showing results for 
Search instead for 
Did you mean: 

Can't change section format properties in codebehind

Former Member
0 Kudos

I have the following code in my aspx page:

CrystalDecisions.CrystalReports.Engine.ReportDocument cryRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

cryRpt.Load(path1);

ReportClientDocumentWrapper docWrap = (ReportClientDocumentWrapper)cryRpt.ReportClientDocument;

AddReportDetailsSection(docWrap, detailsA.Width, detailsA.Height, "detailsC");

var detailsC = docWrap.ReportDefController.ReportDefinition.DetailArea.Sections[2];

if (detailsC != null)

{

      detailsC.Format.EnableNewPageAfter = true;

      detailsC.Format.PageOrientation = CrPaperOrientationEnum.crPaperOrientationLandscape;

      docWrap.SubreportController.ImportSubreport("1sub", path2, detailsC);

}

var subReports = docWrap.ReportDefController.ReportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindSubreport);

foreach (var subReport in subReports) {

           var iSubReport = subReport as ISCRSubreportObject;

            iSubReport.Border.BottomLineStyle = iSubReport.Border.RightLineStyle

            = iSubReport.Border.TopLineStyle = iSubReport.Border.LeftLineStyle = CrLineStyleEnum.crLineStyleNoLine;

}

cryRpt.SaveAs(path2);

But when I open saved report via SAP Crystal Reports Developer, i see that subreport was added with borders and details section C formatting wasn't changed. Can somebody tell me, what I'm missing?

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

The code looks good. However there were (possibly still are) issues with setting all kinds of print options. Lots of info on that in these forums. there have also been a number of fixes for print issues. Unfortunately, you don't mention version of CR or Service pack you might be using(?). Also, what version of VS?

- Ludek

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Share Your Knowledge in SCN Topic Spaces

Former Member
0 Kudos

HI,

thank you for reply. My CR version is 13.0.2000, VS 2010.

I've found some workaround.

To get report objects i've written such method:

protected static List<T> GetReportObjects<T>(CrystalDecisions.CrystalReports.Engine.ReportDocument report) where T

                                                                                        : class

        {

            List<T> resList = new List<T>();

            IEnumerator re = report.ReportDefinition.ReportObjects.GetEnumerator();

            re.Reset();

            while (re.MoveNext())

            {

                if (re.Current != null)

                {

                    var obj = re.Current as T;

                    if (obj != null)

                    {

                        resList.Add(obj);

                    }

                }

            }

            return resList;

        }

And then I use it like below:

var subRptObj = GetReportObjects<CrystalDecisions.CrystalReports.Engine.SubreportObject>(rptDoc).Where(s => s.Name.Equals("1sub")).SingleOrDefault();


if (subRptObj != null)

{

   subRptObj.Border.BottomLineStyle = LineStyle.DotLine;

}

Maybe, this will help somebody.

Former Member
0 Kudos

I had to change

...Where(s => s.Name.Equals("1sub")).SingleOrDefault();

to

...Where(s => s.SubreportName.Equals("1sub")).SingleOrDefault();

but now it works. thank you. you are my hero.

Answers (0)