首页 文章

通过c#将值从winform传递到crystal report文本对象

提问于
浏览
0

我是C#编程的新手,也是Crystal Report的新手 . 我发现用户从WinForm输入的值通过C#(VS10)显示在Crystal Report上时遇到问题 . 我只需要在Report Header中将输入值显示为文本对象 . 我已经找了解决方案,但我仍然不知道我的代码有什么问题 .

我创建了一个连接到其查看器的水晶报告 . 这是我的WinForm代码

private void btnSubmit_Click(object sender, EventArgs e)
{
     crRpt TI = new crRpt();            
     CrystalReportViewer crv = new CrystalReportViewer();

     TextObject tiNo = (TextObject)TI.ReportDefinition.Sections["Section2"].ReportObjects["TIN"];
     tiNo.Text = txtTI.Text.toString();
     crv.Visible = false;            
     crv.ReportSource = TI;
     ShowDialog(crv);                     
}

它返回一个错误说:

已显示的表单无法显示为模式对话框 . 在调用showDialog之前,将表单的visible属性设置为false .

即使我已经把 - > crv.visible = false .

我从Crystal Report Viewer中看到,WinForm自动生成一个代码,以显示连接到excel文件作为其数据源的报告 . 如果我在代码底部添加2行代码,如下所示:

displayCR_form dispCR = new displayCR_form();
dispCR.ShowDialog();

和评论 - > ShowDialog(crv);

报告将出现但仍包含我已分配的空白文本对象 . 我错过了什么?请帮忙 . 谢谢 .

1 回答

  • 0
    private void btnSubmit_Click(object sender, EventArgs e)
    {
         crRpt TI = new crRpt();            
         CrystalReportViewer crv = new CrystalReportViewer();
         Form frmCrViewer = new Form();
         frmCrViewer.Controls.Add(crv);
    
         TextObject tiNo = (TextObject)TI.ReportDefinition.Sections["Section2"].ReportObjects["TIN"];
         tiNo.Text = txtTI.Text.toString();
         crv.ReportSource = TI;
         crv.Dock = Fill;
         frmCrViewer.ShowDialog();
    }
    

相关问题