C# 使用 Microsoft.Reporting.WinForms 动态加载嵌入式资源报告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/162989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:19:30  来源:igfitidea点击:

Dynamically Load Embedded Resource Report Using Microsoft.Reporting.WinForms

c#reporting-servicesreport

提问by Craig Eddy

How does one dynamically load a new report from an embedded resource? I have created a reporting project that contains a report as an embedded resource. I added a second report file and use the following code to switch reports:

如何从嵌入式资源动态加载新报告?我创建了一个报告项目,其中包含一个作为嵌入式资源的报告。我添加了第二个报告文件并使用以下代码切换报告:

this.reportViewer1.LocalReport.ReportEmbeddedResource = "ReportsApplication2.Report2.rdlc";
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();

When this code executes, the original report remains visible in the report viewer.

执行此代码时,原始报表在报表查看器中仍然可见。

I have also tried using

我也试过使用

LocalReport.LoadReportDefinition

but had the same result.

但结果相同。

采纳答案by Craig Eddy

The answer: you have to call

答案:你必须打电话

<ReportViewer>.Reset();

prior to changing the value of ReportEmbeddedResource or calling LoadReportDefinition.

在更改 ReportEmbeddedResource 的值或调用 LoadReportDefinition 之前。

After you do so, you'll also have to call

在你这样做之后,你还必须打电话

<ReportViewer>.LocalReport.DataSources.Add( ... );

to re-establish the data sources.

重新建立数据源。