如何在ReportViewer c#中生成子报表中的图表

本文关键字:报表 ReportViewer | 更新日期: 2023-09-27 18:16:41

我目前正在开发一个WPF应用程序,我使用包含一个图表的ReportViewer,但我需要在我的报告中显示另一个图表。我创建了一个子报表,并在主报表中调用它。但是如果我在子报告中插入图表不工作!The Subreport1 could not be found at the specified location. Please verify that the subreport has been published and that the name is correct.如果我使用表格或文本框,它可以工作,但如果使用图表则不行。这是我的代码后面:

private void showReport(object sender, RoutedEventArgs e)
        {

            RVInfoGrafico.Reset();
            RVInfoGrafico.LocalReport.DataSources.Clear();
            RVInfoGrafico.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MSubreportProcessingEventHandler);
            DataTable dt = GetData2();
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            RVInfoGrafico.LocalReport.DataSources.Add(rds);
            RVInfoGrafico.LocalReport.ReportEmbeddedResource = "Project.Info.rdlc";
            RVInfoGrafico.ProcessingMode = ProcessingMode.Local;
            RVInfoGrafico.RefreshReport();
        }
        void MSubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
        {
            DataTable dt9 = GetData4();
            e.DataSources.Add(new ReportDataSource("DataSet1",dt9));
        }

如何在ReportViewer c#中生成子报表中的图表

错误提示无法找到Subreport1。也许尝试直接使用LoadSubreportDefinition("Subreport1",xxx)提供它?

像这样:

var asm = Assembly.GetExecutingAssembly();
var stream = asm.GetManifestResourceStream("RVInfoGrafico.Reports.Subreport.rdlc"); // Change to your path or get a stream of it some other way
RVInfoGrafico.LocalReport.LoadSubreportDefinition("Subreport1", stream);

供参考-在我做过的一个项目中,.rdlc文件在VisualStudio中的Build Action被设置为"Embedded Resource"