CrystalReportViewer无法在C#中显示

时间:2014-11-04 06:10:53

标签: c# crystal-reports

我正在尝试显示crystal report in a crystal report viewer in C# using Visual Studio 2005,但查看器对象在"tempCover.Load"可以执行时不会显示报告。

这似乎是一个与此相关的问题: CrystalReportViewer deployment

我的代码有问题吗?非常感谢。

public void PreviewReport() 
{
    ReportDocument tempCover = new ReportDocument();
    tempCover.Load(@"test.rpt");
    using (Form form = new Form()) 
    {
        writeLog("new form");
        CrystalReportViewer tempViewer = new CrystalReportViewer();
        tempViewer.ReportSource = tempCover;
        writeLog(Convert.ToString(tempViewer.ReportSource));
        tempViewer.AutoSize = true;
        tempViewer.Refresh();
        form.Controls.Add(tempViewer);
        form.AutoSize = true;
        form.ShowDialog();
    }
}

log file

3:45:37 PM : new form
3:45:37 PM : CrystalDecisions.CrystalReports.Engine.ReportDocument

1 个答案:

答案 0 :(得分:0)

修复代码后,如下所示成功显示报告。

public void PreviewReport() 
{
    ReportDocument tempCover = new ReportDocument();
    tempCover.Load(@"test.rpt");
    using (Form form = new Form()) 
    {
        writeLog("new form");
        CrystalReportViewer tempViewer = new CrystalReportViewer();

        tempViewer.ActiveViewIndex = -1;
        tempViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        tempViewer.Dock = System.Windows.Forms.DockStyle.Fill;
        tempViewer.Name = "tempViewer";
        tempViewer.SelectionFormula = "";
        tempViewer.TabIndex = 0;
        tempViewer.ViewTimeSelectionFormula = "";

        tempViewer.ReportSource = tempCover;
        writeLog(Convert.ToString(tempViewer.ReportSource));
        tempViewer.AutoSize = true;
        tempViewer.Refresh();
        form.Controls.Add(tempViewer);
        form.AutoSize = true;
        form.ShowDialog();
    }
}