HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress

Sunday, July 22, 2012

Create a Static Report

To create a simple report, do the following.
Create an Application and Add a Report
1.      Run Microsoft® Visual Studio® (2008 or 2010).
2.      Start a new project (CTRL+SHIFT+N), and create a new Windows Forms Application.
3.      On the Project menu, choose Add New Item... (or press CTRL+SHIFT+A) to invoke the Add New Item dialog.
In this dialog, choose the XtraReport Class v12.1 item and click Add. This will add a new blank report to your application.
Alternatively, you can choose the XtraReport Wizard v12.1 template, which invokes the Report Wizard that is intended for quick creation of classic reports.
Construct the Report
5.      Now the Visual Studio shows the designer for the newly created report (by default it is called XtraReport1; this name will be used in the current lesson). Note that this report is derived from the XtraReport class, which is the base class for all reports. You may find this behavior similar to the one introduced when you're creating a new form class, which is derived from the base System.Windows.Forms.Form class.
To proceed with report creation, open the Toolbox pane (by pressing CTRL+ALT+X), then select the XRLabel control in the DX.12.1: Report Controls tab and drop it onto the report's Detail Band.
6.      Double-click the created label to invoke its in-place editor, which allows you to input text. For example, type the classic Hello World! statement. Then use the XtraReports toolbar to adjust the label's color and font options.
7.      Now switch to the Preview tab via the Preview button at the bottom.
Also, if you want to see how this report will look as HTML, switch to the HTML View tab.
Output the Report
8.      Now switch to the Form1's designer and add three System.Windows.Forms.Button controls to it. Change their text to Preview, Print and Edit, appropriately.
9.      Write the following Click event handlers for these buttons.
C#
VB
private void button1_Click(object sender, EventArgs e) {
    // Create a report. 
    XtraReport1 report = new XtraReport1();
 
    // Show the report's preview. 
    report.ShowPreview();
}
 
private void button2_Click(object sender, EventArgs e) {
    // Create a report. 
    XtraReport1 report = new XtraReport1();
 
    // Print the report. 
    report.Print();
}
 
private void button3_Click(object sender, EventArgs e) {
    // Create a report. 
    XtraReport1 report = new XtraReport1();
 
    // Open the report in the End-User Designer. 
    report.ShowDesigner();
}
10.  Alternatively, you can preview a report on an arbitrary form. To learn more on this, refer to How to: Show a Report's Preview on a Form.
Get the Result
Run the application. Click the Preview button to invoke the Preview window containing the created Hello World! report. To print the report, just click the Print button.


Enhanced by Zemanta

No comments:

Post a Comment