C# 子报表处理事件未触发
我在WPF中使用rdlc报告,所以我使用WindowsFormsHost包装器。我正在寻找的rdlc报告中嵌入了一个子报告,我正在使用ReportViewer的SubreportProcessing事件设置该子报告的数据源C# 子报表处理事件未触发,c#,wpf,rdlc,subreport,C#,Wpf,Rdlc,Subreport,我在WPF中使用rdlc报告,所以我使用WindowsFormsHost包装器。我正在寻找的rdlc报告中嵌入了一个子报告,我正在使用ReportViewer的SubreportProcessing事件设置该子报告的数据源 Viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LoadAccessoriesSubReport); private void PrepareReport(V
Viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LoadAccessoriesSubReport);
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;
我的问题是SubreportProcessing事件甚至没有被触发。我在包含嵌入式ReportViewer控件的WPF窗口的窗口\u Loaded
事件中定义它,请参见下面的xaml:
Title="ReportViewer" Height="1000" Loaded="Window_Loaded" Width="1000">
<Grid>
<WindowsFormsHost Name="winHost">
<wf:ReportViewer Dock="Fill" Name="rptViewer">
</wf:ReportViewer>
</WindowsFormsHost>
</Grid>
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;
Title=“ReportViewer”Height=“1000”load=“Window\u load”Width=“1000”>
如果您能在这方面提供帮助,我将不胜感激。我也遇到了同样的问题,在WPF应用程序中使用LocalReport而不使用ReportViewer
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;
但结果是,我试图将空值作为参数从父报表传递到子报表
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;
因此,子报表从未开始呈现。这就是事件未触发的原因。检查子报表参数。如果参数条件失败,则不会加载子报表。
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;
还要检查Visual Studio跟踪输出,它会显示导致错误的参数
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;
为了执行快速检查,请将所有子报表参数设置为允许null
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;
它帮了我的忙(现在,我只需要理解为什么我会得到一个空值而不是期望的值:)尝试设置ReportName属性以匹配报表文件名。这里也有同样的问题,尽管这个问题可能有点老了。。
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;
如果要从代码隐藏分配数据源,请确保在将数据源添加到主报表后添加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()
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;
我以前被添加到AddHandler部分,但该事件从未被触发。希望这能帮助有同样问题的人。在主报表和子报表自身的子报表控件上添加匹配参数
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;
这就是我设法使它工作的方式,可能不是最好的解决方案……它使用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;
private void PrepareReport(查看TravelOrderEmployees travelOrder)
{
实体=新实体();
this.mform_components=new System.ComponentModel.Container();
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1=新的Microsoft.Reporting.WinForms.ReportDataSource();
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource2=新的Microsoft.Reporting.WinForms.ReportDataSource();
this.ProductBindingSource=new System.Windows.Forms.BindingSource(this.mform\u组件);
this.ProductBindingSource2=new System.Windows.Forms.BindingSource(this.mform\u组件);
reportDataSource1.Name=“ViewTravelOrderEmployees”;
reportDataSource1.Value=this.ProductBindingSource;
//DAL_目的地是rdlc中的子报表->属性->常规->名称
reportDataSource2.Name=“DAL_目的地”;
reportDataSource2.Value=this.ProductBindingSource2;
this.reprt.LocalReport.DataSources.Add(reportDataSource1);
this.reprt.LocalReport.DataSources.Add(reportDataSource2);
this.reprt.LocalReport.SubreportProcessing+=新的SubreportProcessingEventHandler(SubreportProcessingEventHandler);
this.reprt.LocalReport.ReportEmbeddedResource=“PNWPF.TravelOrder.rdlc”;
字符串exeFolder=System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.StartupPath);
字符串reportPath=System.IO.Path.Combine(exeFolder,@“Reports\TravelOrder.rdlc”);
this.reprt.LocalReport.ReportPath=ReportPath;
this.ProductBindingSource.DataSource=travelOrder;
this.reprt.RefreshReport();
}
无效SubreportProcessingEventHandler(对象发送方,SubreportProcessingEventArgs e)
{
实体=新实体();
字符串dataSourceName=e.DataSourceNames[0];
//查询需要完成这只是一个例子
List destinations=entities.destinations.ToList();
e、 添加(新的ReportDataSource(dataSourceName,destinations));
}
PNA实体;
private System.ComponentModel.IContainer mform_components=null;
private System.Windows.Forms.BindingSource产品BindingSource;
private System.Windows.Forms.BindingSource产品BindingSource2;
XAML
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;
我也遇到了同样的问题,发现
ReportViewer1.Reset()
正在清除事件处理程序。在ReportViewer1.Reset()之后立即将AddHandler行移动到解决了问题。我也有同样的问题。我还没有找到一个解决方案……虽然没有直接回答我的问题,但问题的细节回答了我的问题。谢谢+1你的回答引导我走向正确的方向,谢谢。现在我知道主报表和子报表中的参数(即用作子报表的报表文件和子报表属性中的子报表参数)出现任何问题都会阻止事件的引发。
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;