在单独的表单上预览Crystal Report

时间:2012-10-15 14:06:18

标签: c# winforms crystal-reports-xi

我有一个表单,允许用户选择他们想要生成的报告。他们还可以选择条件,选择打印,预览,导出等。用户进行选择并单击“生成”按钮后,我有一个类创建报表对象,加载报表,数据集,然后打印或导出那个报告。我创建了一个单独的表单来预览报表。当我将报表对象传递给预览表单时,我收到“无效的报表源”。报告打印和导出就好了,我只是无法预览报告。我不想在预览表单中复制代码,我希望我可以只传递报表对象。我的代码片段如下。有什么建议吗?

public static class CrystalReportUtilities
{
    private static ReportDocument goReport {get; set;}
    private static string gsReportName { get; set; }
    private static string gsSqlString { get; set; }
    private static object[,] goParameters { get; set; }

    public static void generateReport(parameters...)
    {
      goReport = loadReport();
...
      goReport.SetDataSource(DataTable);
...
      previewReport();


    private static void previewReport()
    {
        CrystalReportPrintPreviewForm loReportPreview = new CrystalReportPrintPreviewForm(goReport);
        loReportPreview.ShowDialog();
    }


public partial class CrystalReportPrintPreviewForm : Form
{
    private ReportDocument goReport;

    public CrystalReportPrintPreviewForm(ReportDocument poReport)
    {
        InitializeComponent();

        goReport = poReport;
    }

    private void crystalReportViewer1_Load(object sender, EventArgs e)
    {
        try
        {
            if (goReport != null)
            {
                crystalReportViewer1.ReportSource = goReport;  // Receive "Invalid Report Source"
            }
        }

1 个答案:

答案 0 :(得分:0)

问题已解决。我在Windows 7,64位操作系统上运行。我最初为64位Visual Studio 2010安装了Crystal Reports。看来你需要使用SP4的64位和32位版本的运行时。