3

我在 WPF 中使用 rdlc 报告,所以使用 WindowsFormsHost 包装器这样做。我正在寻找运行的 rdlc 报告中嵌入了一个子报告,我正在使用 ReportViewer 的 SubreportProcessing 事件设置该报告的数据源。

Viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LoadAccessoriesSubReport);

我的问题是 SubreportProcessing 事件甚至没有被触发。我在Window_Loaded包含嵌入式 ReportViewer 控件的 WPF 窗口中定义它,请参见下面的 xaml:

       Title="ReportViewer" Height="1000" Loaded="Window_Loaded" Width="1000">
<Grid>
    <WindowsFormsHost Name="winHost">
        <wf:ReportViewer  Dock="Fill" Name="rptViewer">
        </wf:ReportViewer>  
    </WindowsFormsHost>                   
</Grid>

将不胜感激任何帮助。

4

7 回答 7

8

检查您的子报表参数。如果参数条件失败,则不会加载子报表。还要检查 Visual Studio 跟踪输出,它会显示导致错误的参数。

为了执行快速检查,请将所有子报表参数设置为允许为空。

它对我有用(现在,我只需要了解为什么我得到一个空值而不是预期的值:))

于 2010-02-15T16:19:54.227 回答
2

我遇到了同样的问题,发现ReportViewer1.Reset()正在清除事件处理程序。ReportViewer1.Reset()解决问题后立即移动 AddHandler 行。

于 2012-05-24T17:03:45.220 回答
1

这就是我设法使它工作的方法可能不是最好的解决方案....它使用 EF 和 WPF

    private void PrepareReport(ViewTravelOrderEmployees travelOrder)
    {
        entities = new PNEntities();            

        this.mform_components = new System.ComponentModel.Container();
        Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
        Microsoft.Reporting.WinForms.ReportDataSource reportDataSource2 = new Microsoft.Reporting.WinForms.ReportDataSource();

        this.ProductBindingSource = new System.Windows.Forms.BindingSource(this.mform_components);
        this.ProductBindingSource2 = new System.Windows.Forms.BindingSource(this.mform_components);            

        reportDataSource1.Name = "ViewTravelOrderEmployees";
        reportDataSource1.Value = this.ProductBindingSource;
        //DAL_Destination is Subreport -> Properties -> General -> Name in rdlc
        reportDataSource2.Name = "DAL_Destinations";
        reportDataSource2.Value = this.ProductBindingSource2;

        this.reprt.LocalReport.DataSources.Add(reportDataSource1);
        this.reprt.LocalReport.DataSources.Add(reportDataSource2);

        this.reprt.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubreportProcessingEventHandler);            

        this.reprt.LocalReport.ReportEmbeddedResource = "PNWPF.TravelOrder.rdlc";
        string exeFolder = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.StartupPath);
        string reportPath = System.IO.Path.Combine(exeFolder, @"Reports\TravelOrder.rdlc");
        this.reprt.LocalReport.ReportPath = reportPath;

        this.ProductBindingSource.DataSource = travelOrder;            
        this.reprt.RefreshReport();             
    }

        void SubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
    {
        entities = new PNEntities();

        string dataSourceName = e.DataSourceNames[0];
        //query needs to be completed this is just example
        List<Destinations> destinations = entities.Destinations.ToList();            

        e.DataSources.Add(new ReportDataSource(dataSourceName, destinations));
    }

    PNEntities entities;
    private System.ComponentModel.IContainer mform_components = null;
    private System.Windows.Forms.BindingSource ProductBindingSource;
    private System.Windows.Forms.BindingSource ProductBindingSource2;

XAML

<Window x:Class="PNWPF.frmReportWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:viewer="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
Title="frmReportWindow" Height="300" Width="300">
<Grid>
    <wfi:WindowsFormsHost Name="winfrmHost">
        <viewer:ReportViewer x:Name="reprt">

        </viewer:ReportViewer>
    </wfi:WindowsFormsHost>
</Grid>

于 2012-04-11T09:07:03.840 回答
1

在主报表的子报表控件和子报表本身上添加匹配参数。

  1. 在主报表上右键单击子报表控件 -> 属性... -> 添加“InvoiceId”“[InvoiceId]”
  2. 在子报表上 -> 点击任意位置 -> 查看 -> 报表数据 -> 参数 -> 添加“InvoiceId”
于 2012-02-15T02:24:57.167 回答
1

这里有同样的问题,即使这个问题可能有点老了。如果您从后面的代码中分配数据源,请确保在将数据源添加到主报告之后添加 SubreportProcessing 事件的处理程序。我是这样做的:

Dim rpDataSource As New ReportDataSource("sourceMain", myDataTable1)
Dim rpDataSourceSub As New ReportDataSource("sourceSub", myDataTable2)

ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.EnableHyperlinks = False
ReportViewer1.Reset()
Me.ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(AppDomain.CurrentDomain.Evidence)
ReportViewer1.LocalReport.ReportPath = "Reports\report1.rdlc"
ReportViewer1.LocalReport.DisplayName = "Report" + Today.ToString("dd-MM-yyyy")
ReportViewer1.LocalReport.Refresh()

If Not ReportViewer1.LocalReport.DataSources.Contains(rpDataSource) Then
  ReportViewer1.LocalReport.DataSources.Add(rpDataSource)
End If

If Not ReportViewer1.LocalReport.DataSources.Contains(rpDataSourceSub) Then
  ReportViewer1.LocalReport.DataSources.Add(rpDataSourceSub)
End If

AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SetSubDataSource
Me.ReportViewer1.LocalReport.Refresh()

我之前添加了 AddHandler 部分,并且该事件从未被触发。希望这会帮助有同样问题的人。

于 2011-12-09T09:57:55.567 回答
0

我遇到了同样的问题,在 WPF 应用程序中使用 LocalReport 而不使用 ReportViewer。

但事实证明,我试图将一个空值作为参数从父报表传递到子报表。

因此,子报表从未开始呈现。这就是事件没有被触发的原因。

于 2010-01-18T21:05:36.817 回答
0

Try setting ReportName property to match the report file name.

于 2011-03-04T11:31:47.717 回答