CrystalReportViewer未在C#中显示

本文关键字:显示 未在 CrystalReportViewer | 更新日期: 2023-09-27 18:29:02

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

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

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

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

CrystalReportViewer未在C#中显示

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

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();
    }
}