VS2010 RDLC C#.如何将LocalReport对象设置为ReportViewer? [英] VS2010 RDLC C#. How can I set a LocalReport object to a ReportViewer?

查看:193
本文介绍了VS2010 RDLC C#.如何将LocalReport对象设置为ReportViewer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LocalReport对象,我用所有适当的信息填充了该对象.我使用相同的报表对象导出为不同的格式.我的用户可以选择图像","Excel","Word","Pdf"等.我使用相同的报表对象来简化这些请求.

I have a LocalReport object that I fill with all the apropriate information. I use this same report object to export to different formats. My users can select Image, Excel, Word, Pdf, etc. and I use the same report object to facilitate those request.

我的问题是有时他们可能想查看它.我知道我可以打开导出的类型,但这不是我想要的.我想在ReportViewer中查看它.我知道我可以设置ReportViewer.LocalReports属性并获得所需的内容,但是我已经在Report对象中设置了所有内容.

My issue is sometimes they may want to view it. I know I can open the exported type but that is not what I want to happen. I want to view it in a ReportViewer. I know I can set ReportViewer.LocalReports properties and get what I'm looking for , but I already set everything up in my Report object.

所以问题是:我该如何处理不正确且无法完成的关注?

LocalReport _Report = new LocalReport();

//set all my report information

Microsoft.Reporting.WinForms.ReportViewer _rv = new Microsoft.Reporting.WinForms.ReportViewer();

//This is what I'm trying to do
 _rv.LocalReport = _Report;

推荐答案

您可以尝试更改当前执行的操作顺序.

You can try by altering the order of things you are currently doing.

  1. 将ReportViewer添加到表单. (我不确定为什么要用代码创建ReportViewer.我相信您不会将其动态添加到表单控件中.)

  1. Add a ReportViewer to the form. (I am not sure why you are creating the ReportViewer in code. I believe you are not going to dynamically add it to the controls of the form.)

在ReportViewer.LocalReport对象中设置所有报告信息.无需像在第一行代码中那样创建它.

Set all your report information in the ReportViewer.LocalReport object. No need to create it like you have done it in your first line of code.

调用ReportViewer.RefreshReport()方法以在表单上呈现报告.

Call ReportViewer.RefreshReport() method to render the report on the form.

PS:如果已经有了LocalReport对象,则必须将其中的属性分配给ReportViewer上的报告对象.

PS: If you already have a LocalReport object, you will have to assign the properties from that to the report object on the ReportViewer.

这篇关于VS2010 RDLC C#.如何将LocalReport对象设置为ReportViewer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆