开发者

How do I programmatically import a Crystal Reports SubReport into a Report Section in Visual Studio 2010

I have a Crystal Report object defined as follows:

private CrystalDecisions.CrystalReports.Engine.ReportClass rep;

I am trying to Import a SubReport into Section 1 of the report. I have tried variants of the following code: rep.ReportClientDocument.SubreportController.ImportSubreport

There seems to be conflict between:

开发者_开发知识库
CrystalDecisions.CrystalReports.Engine

and

CrystalDecisions.ReportAppServer

Has anybody programmatically imported a Sub-Report in Crystal using VS2010?


For anybody else who comes across this problem, the solution is:

            CrystalDecisions.CrystalReports.Engine.ReportClass rep;
            ReportClientDocumentWrapper doc = (ReportClientDocumentWrapper)rep.ReportClientDocument;
            CrystalDecisions.ReportAppServer.ReportDefModel.Section sec = doc.ReportDefController.ReportDefinition.ReportHeaderArea.Sections[0];
            doc.SubreportController.ImportSubreport("SubReport", csr.ReportFileName, sec);
            rep.OpenSubreport("SubReport").SetDataSource(csr.ds.Tables[0]);


For anyone who still might need this. Here is the solution. Try it and work!!!

You need to import these References:

  • CrystalDecisions.ReportAppServer.ClientDoc
  • CrystalDecisions.ReportAppServer.Controllers
  • CrystalDecisions.ReportAppServer.ReportDefModel

here is the code:

ReportDocument rpt = new ReportDocument();

rpt.Load("reportPath"));

rpt.SetDataSource(dt);

Inside the main report you must have a subreport and with this code it re-import from the dynamic path

CrystalDecisions.ReportAppServer.ReportDefModel.Section sec = rpt.ReportClientDocument.ReportDefController.ReportDefinition.PageHeaderArea.Sections[0];
rpt.ReportClientDocument.SubreportController.ImportSubreport("subreportname", "subreportpath", sec);


Adding sub-reports dynamically is not supported in Crystal Reports as of now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜