Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Visual Studio LocalReport对象和ReportViewer_Vb.net_Reporting Services_Report_Reportviewer_Localreport - Fatal编程技术网

Vb.net Visual Studio LocalReport对象和ReportViewer

Vb.net Visual Studio LocalReport对象和ReportViewer,vb.net,reporting-services,report,reportviewer,localreport,Vb.net,Reporting Services,Report,Reportviewer,Localreport,是否有方法处理LocalReport对象(完成此部分),并在ReportViewer控件的另一个窗体上显示它?其想法是在没有ReportViewer的情况下打印(已经完成),但是,如果用户想要,也可以预览他将要打印的内容 我正在使用Visual Basic.NET SDK 3.5和Visual Studio 2008。如果需要,也可以使用2010 我试着这样做: ReportViewer1.LocalReport = myLocalReport 但是运气不好,因为ReportViewer上的

是否有方法处理
LocalReport
对象(完成此部分),并在
ReportViewer
控件的另一个窗体上显示它?其想法是在没有ReportViewer的情况下打印(已经完成),但是,如果用户想要,也可以预览他将要打印的内容

我正在使用Visual Basic.NET SDK 3.5和Visual Studio 2008。如果需要,也可以使用2010

我试着这样做:

ReportViewer1.LocalReport = myLocalReport 
但是运气不好,因为
ReportViewer
上的
LocalReport
属性是只读的

有什么提示吗?提前谢谢


(我知道要使用
ReportViewer1.LocalReport
方法执行此操作。我只想创建一个代码并将其直接绑定到打印机或预览表单)

本地报告是只读的,但ReportPath和ReportEmbeddedResource是可设置的

尝试类似的方法,或者如果您的报表未嵌入,请尝试设置LocalReport的ReportPath属性

reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("GravatomsReportRegister", GravatomsFullInfoByIdBindingSource));
            reportViewer1.LocalReport.ReportEmbeddedResource = "Gravatun.GraviGrancumReport.rdlc";
            reportViewer1.RefreshReport();

LocalReport是只读的,但ReportPath和ReportEmbeddedResource是可设置的

尝试类似的方法,或者如果您的报表未嵌入,请尝试设置LocalReport的ReportPath属性

reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("GravatomsReportRegister", GravatomsFullInfoByIdBindingSource));
            reportViewer1.LocalReport.ReportEmbeddedResource = "Gravatun.GraviGrancumReport.rdlc";
            reportViewer1.RefreshReport();

我有一个与您类似的情况,我有可以创建本地报告的服务,然后可以生成PDF、通过电子邮件发送等。但是,由于ReportViewer.LocalReport是只读属性,我必须复制用于生成报告的代码,或者将值从我的LocalReport复制到ReportViewer.LocalReport。我不喜欢这两种选择,因为有些东西可能无法复制(即子报告事件),或者存在代码重复

我提出了以下扩展,它在带有反射的ReportViewer上设置LocalReport。我还没有完全测试这个,这可能是一个坏主意!然而,它似乎对我目前正在进行的项目有效。我不知道ReportViewer是否对它的本地报告进行了一些额外的初始化,因此可能会发生一些事情

这一点我再强调也不为过——使用风险自负——这可能不是一个好主意

public static class ReportViewerExtensions
{
    public static void SetLocalReport(this ReportViewer reportViewer, LocalReport report)
    {
        var currentReportProperty = reportViewer.GetType().GetProperty("CurrentReport", BindingFlags.NonPublic | BindingFlags.Instance);
        if (currentReportProperty != null)
        {
            var currentReport = currentReportProperty.GetValue(reportViewer, null);
            var localReportField = currentReport.GetType().GetField("m_localReport", BindingFlags.NonPublic | BindingFlags.Instance);
            if (localReportField != null)
            {
                localReportField.SetValue(currentReport, report);
            }
        }
        reportViewer.RefreshReport();
    }
}
用法:

LocalReport localReport = reportService.GenerateCurrentOrdersReport(....);
reportViewer.SetLocalReport(localReport);

我有一个与您类似的情况,我有可以创建本地报告的服务,然后可以生成PDF、通过电子邮件发送等。但是,由于ReportViewer.LocalReport是只读属性,我必须复制用于生成报告的代码,或者将值从我的LocalReport复制到ReportViewer.LocalReport。我不喜欢这两种选择,因为有些东西可能无法复制(即子报告事件),或者存在代码重复

我提出了以下扩展,它在带有反射的ReportViewer上设置LocalReport。我还没有完全测试这个,这可能是一个坏主意!然而,它似乎对我目前正在进行的项目有效。我不知道ReportViewer是否对它的本地报告进行了一些额外的初始化,因此可能会发生一些事情

这一点我再强调也不为过——使用风险自负——这可能不是一个好主意

public static class ReportViewerExtensions
{
    public static void SetLocalReport(this ReportViewer reportViewer, LocalReport report)
    {
        var currentReportProperty = reportViewer.GetType().GetProperty("CurrentReport", BindingFlags.NonPublic | BindingFlags.Instance);
        if (currentReportProperty != null)
        {
            var currentReport = currentReportProperty.GetValue(reportViewer, null);
            var localReportField = currentReport.GetType().GetField("m_localReport", BindingFlags.NonPublic | BindingFlags.Instance);
            if (localReportField != null)
            {
                localReportField.SetValue(currentReport, report);
            }
        }
        reportViewer.RefreshReport();
    }
}
用法:

LocalReport localReport = reportService.GenerateCurrentOrdersReport(....);
reportViewer.SetLocalReport(localReport);