Visual studio 2010 如何从VS2010启动crystal reports viewer?

Visual studio 2010 如何从VS2010启动crystal reports viewer?,visual-studio-2010,crystal-reports,Visual Studio 2010,Crystal Reports,我已经安装了CR_for_VS_13_0_4.exe程序,在所有这些帖子中都链接到该程序,但我不知道实际启动“.rpt”文件需要使用什么代码。我正在使用: process.start("myfile.rpt") 但它启动的是报表设计器,而不是查看器。如何确保它在运行我的应用程序的客户端上启动查看器 谢谢。通过使用myfile.rpt启动进程,您告诉Windows使用与.rpt文件关联的程序打开文件:在您的机器上,这可能是CR设计器;在用户的计算机上,可能没有与.rpt文件关联的程序 我认为您需

我已经安装了CR_for_VS_13_0_4.exe程序,在所有这些帖子中都链接到该程序,但我不知道实际启动“.rpt”文件需要使用什么代码。我正在使用:

process.start("myfile.rpt")
但它启动的是报表设计器,而不是查看器。如何确保它在运行我的应用程序的客户端上启动查看器


谢谢。

通过使用
myfile.rpt
启动进程,您告诉Windows使用与
.rpt
文件关联的程序打开文件:在您的机器上,这可能是CR设计器;在用户的计算机上,可能没有与
.rpt
文件关联的程序

我认为您需要做的不是“启动”
myfile.rpt
,而是实例化一个CR查看器对象,并将其显示的报告设置为
myfile.rpt

考虑一个关于在VS2010中使用CR查看器的例子

更新:

关于您的评论,即您正在为所有内容编写代码,而不是使用VS工具箱,我下载并修改了一点,以便为您成功地PoC以下内容:

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        // the CR viewer
        private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;

        public Form1()
        {
            InitializeComponent();

            // 
            // crystalReportViewer1
            // 
            this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();

            // FORNOW: just some "who cares" setup assignments for PoC - to be adjusted of course
            this.crystalReportViewer1.ActiveViewIndex = -1;
            this.crystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.crystalReportViewer1.Cursor = System.Windows.Forms.Cursors.Default;
            this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);
            this.crystalReportViewer1.Name = "crystalReportViewer1";
            this.crystalReportViewer1.Size = new System.Drawing.Size(150, 150);
            this.crystalReportViewer1.TabIndex = 3;

            // FORNOW: a DataSet1 as a dummy data source for PoC - really to be loaded with meaningful data of course
            DataSet1 ds1 = new DataSet1();
            ds1.Tables["DataTable1"].Rows.Add(new object[] { 25 }); // whatever - just some data for PoC

            // the CR document - myfile.rpt
            ReportDocument reportDocument1 = new ReportDocument();
            reportDocument1.Load("myfile.rpt");
            // See the note regarding the next statement that follows the code.
            reportDocument1.SetDataSource(ds1); // set to use our dummy data source for PoC

            // the CR viewer set to use the CR document
            this.crystalReportViewer1.ReportSource = reportDocument1;

            // the CR viewer added to the form's controls
            this.Controls.Add(this.crystalReportViewer1);

            // etcetera
        }

        // etcetera
    }
}

如果您的目标是.NET 4.0,您将在
reportDocument1.SetDataSource(ds1)遇到一个关于
crdb\u adoplus.dll的
FileNotFoundException
除非您将以下内容添加到
app.config

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
</startup>

有关更多信息,请参阅

最后一点注意,虽然这可以在没有VS工具箱的情况下完成,但我强烈建议使用它在表单的
.designer.cs
文件中为CR查看器添加大量设计时代码,并将表单的
.cs
文件集中在提交报告所需的更有意义的代码上。不过,蒂姆托维


报道愉快

我没有使用工具箱将项目添加到我的项目中。我所做的一切都是基于代码的。该链接仅讨论如何使用工具箱。如何从代码中使用查看器?想法是一样的,工具箱只是一种拖放方式,用于实例化查看器控件并将其添加到窗体控件中。我将用一些代码更新我的答案,这些代码显示了我认为您需要走的方向。@user272815,我按照承诺添加了一个带有PoC代码示例的更新。顺便说一句,这导致了非常合适的结果,@user272815!:)