vb.net 如何将多个reports.rdlc 设置为一个报告查看器(编码中)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16767912/
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
How to set many reports.rdlc into one report viewer ( In Coding )
提问by pagejaws
I got a problem in my vb Project, as from subject its clear that I have a problem in specifying many reports in one report viewer in one form. It's difficult to create many forms and adding report viewer in each form.
我在我的 vb 项目中遇到了问题,因为从主题来看,我在以一种形式在一个报告查看器中指定许多报告时遇到了问题。创建多个表单并在每个表单中添加报表查看器是很困难的。
I have more than 100 reports.rdlc and want to show it in one report viewer by choosing multiple options in combobox or different criterias.
我有 100 多个reports.rdlc,并希望通过在组合框中选择多个选项或不同的条件在一个报告查看器中显示它。
回答by Alex
If you want the same form window to appear each time you change report in your combobox, just create a new instance of that form every time you go to generate the .rdlc report.
如果您希望每次更改组合框中的报告时都显示相同的表单窗口,只需在每次生成 .rdlc 报告时创建该表单的新实例。
Button1 Click
按钮 1 单击
When you click this button, it will create two reports. One report will be generated from the method YourFirstReport()and the other from YourSecondReport(). Both using the same ReportViewer1 control from the same form using a new instance of rv.
当您单击此按钮时,它将创建两个报告。一份报告将根据方法生成,YourFirstReport()另一份报告从YourSecondReport(). 两者都使用来自同一表单的相同 ReportViewer1 控件,使用rv.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Create instance "rv" of your report viewer form
Dim rv As New frmReportViewer
rv.YourFirstReport()
rv = New frmReportViewer
rv.YourSecondReport()
End Sub
rv.YourFirstReport()
rv.YourFirstReport()
Public Sub YourFirstReport()
ReportViewer1.LocalReport.ReportEmbeddedResource = "YourProject.YourFirstReportName"
'...
'And so on..
End Sub
rv.YourSecondReport()
rv.YourSecondReport()
Public Sub YourSecondReport()
ReportViewer1.LocalReport.ReportEmbeddedResource = "YourProject.YourSecondReportName"
'...
'And so on..
End Sub
Take my example here, the square in red has a button that generates my frmReportViewerevery time I click on it. The green circles demonstrate my reports that pop up. Both these report utilize the same form.

以我这里的例子为例,红色方块有一个按钮,frmReportViewer每次我点击它时都会生成我的按钮。绿色圆圈展示了我弹出的报告。这两个报告都使用相同的表格。

回答by pagejaws
Just as tezzo said,
正如 tezzo 所说,
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.ReportPath = "Report2.rdlc"
ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", CType(d1, DataTable)))
ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WebForms.ReportParameter("ReportCriteria", criteria))
ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WebForms.ReportParameter("FileDate", fileDateString))
ReportViewer1.Visible = True
ReportViewer1.DataBind()
Changing the localreport reportpath to a different reportname is all you really need.
将 localreport 报告路径更改为不同的报告名称是您真正需要的。
回答by tezzo
You can create a single ReportViewer and set his property at runtime:
您可以创建一个 ReportViewer 并在运行时设置其属性:
- path to rldc file: .LocalReport.ReportPath
- report datasources: .LocalReport.DataSources
- report parameters: .LocalReport.SetParameters
- other property: for example .LocalReport.EnableExternalImages
- rldc 文件的路径:.LocalReport.ReportPath
- 报告数据源:.LocalReport.DataSources
- 报告参数:.LocalReport.SetParameters
- 其他属性:例如.LocalReport.EnableExternalImages
Then you can .RefreshReport().
然后你可以.RefreshReport()。

