我在 WinForms 应用程序中使用带有 ReportViewer 14.0 的 vs2017。我以前在以前的 VS 版本中做过这个,没有任何问题,我很惊讶为什么这次我不能做这个工作。
这是我到目前为止所做的:
- 我在位于应用程序根目录的 Reports 文件夹中创建了一个报告 (RDLC)。
- 我将 BuildAction 设置为 None 并复制到输出目录以复制(如果较新)
- 在一个新表单中,我放置了 ReportViewer 组件(称为 rpt)
- 我将处理模式设置为本地
- 在表单的 Load 事件中,我运行以下代码:
string path = AppDomain.CurrentDomain.BaseDirectory + @"Reports\Report.rdlc";
rpt.LocalReport.ReportPath = path;
rpt.LocalReport.SetParameters(new ReportParameter("parTitle", Title));
rpt.LocalReport.DataSources.Add(new ReportDataSource("ds", Data));
rpt.Refresh();
当我运行应用程序时,表单会加载,但 ReportViewer 会显示一条消息:尚未指定报告定义
我还尝试将构建操作设置为 EmbeddedResource 并使用:
rpt.LocalReport.ReportEmbeddedResource = "Project.Reports.Report.rdlc";
结果相同。我什至尝试过:
Assembly a = Assembly.GetExecutingAssembly();
Stream report = a.GetManifestResourceStream("Project.Reports.Report.rdlc");
rpt.LocalReport.LoadReportDefinition(report);
没有不同。我总是得到这个:
我已经盯着这个看了几个小时了,在我的一生中,我无法弄清楚我做错了什么。任何帮助将不胜感激。
谢谢你。