Requirements
- Visual Studio 2010 or higher
- Crystal Report for .NET Framework latest version
4(This step is for people who creates the .NET 4.5 project in step 1 only) Open app.config
and place the code below into app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
6Select Dataset and click Add.
17Click OK and Right click on empty space -> Database expert
22Right click on text object -> Format Object
23Name your text object 'TxtHeader'. Note that you can change the textbox programmatically via this name. (see next step)
24Right click on Form1.cs -> View Code
25Place this code in Form1.cs
26Run your application. Congratulations! you made the first crystal report.
Happy Coding!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
namespace CrystalReportSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//generate dummy dataset for report
DataSet1 ds = new DataSet1();
ds.Tables["DataTable1"].Rows.Add("test1", "piyapan");
ds.Tables["DataTable1"].Rows.Add("test2", "xxx");
//link the report file
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(@"c:\users\esri5034\documents\visual studio 2012\Projects\CrystalReportSample\CrystalReportSample\CrystalReport1.rpt");
rptDoc.SetDataSource(ds);
//edit textbox on report file
TextObject txt = (rptDoc.ReportDefinition.ReportObjects["TxtHeader"] as TextObject);
txt.Text = "this is an editing text";
this.crystalReportViewer1.ReportSource = rptDoc;
this.crystalReportViewer1.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None;
this.crystalReportViewer1.EnableDrillDown = false;
this.crystalReportViewer1.RefreshReport();
this.crystalReportViewer1.Refresh();
}
}
}
26Run your application. Congratulations! you made the first crystal report.


























No comments:
Post a Comment