3

我想在不使用任何数据库的情况下创建一个水晶报表我只想显示用户输入的文本。见下图::在此处输入图像描述

我是 C# 表单应用程序的新手

4

1 回答 1

2

假设你是 C#;在设计模式下在水晶报表中创建所需的文本对象(如果没有水晶许可证,您不能动态添加它)。如果您的 WinForm 中有四个值,并且您希望将这些值发布到 Crystal Report 中;您将需要创建四个 TextObject。完成此操作后,只需在按钮单击事件中键入此代码:

/*Initialize the Report Object*/
ReportDocument cryRpt = new ReportDocument();
/*Load the designed report*/
cryRpt.Load(Application.StartupPath + "\\MyReport.rpt");

/*initialize required TextObjects*/
/*SYNTAX :
TextObject objectName = (TextObject)cryRpt.ReportDefinition.Sections["name of report section"].ReportObjects["Name of textobject"];

*/
TextObject txt1 = (TextObject)cryRpt.ReportDefinition.Sections["Section1"].ReportObjects["TextObject1"];


TextObject txt2 = (TextObject)cryRpt.ReportDefinition.Sections["Section1"].ReportObjects["TextObject2"];



/*Pass the text value from WinForm TextBox to Crystal Report TextObject*/
txt1.Text = textbox1.Text;
txt2.Text = textbox2.Text;



/*Create a Form and display the crystal report*/
Form frm = new Form();
frm.Height = 800;
frm.Width = 600;

CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;


crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();

frm.Controls.Add(crystalReportViewer1);
frm.ShowDialog();

就是这样 :) /* 快乐编码 :) */

于 2013-03-26T12:31:30.497 回答