HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress
Showing posts with label Windows Form. Show all posts
Showing posts with label Windows Form. Show all posts

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

Saturday, July 14, 2012

XtraGrid - Binding a Grid to Data

In this lesson, our main goal is to show you how to bind XtraGrid to data. Thus, I’m going to create an extremely simple application that has a single form with Grid Control bound to an access database.
1.       First, let’s drop a Grid Control onto a new form.
2.       And make it fill the entire form’s area.
3.       Now we need to create a data source and bind it to the grid.
4.       These actions can be done at once by the Grid’s smart tag.
5.       I click the “Add Project Data Source…” link to start the “Data Source Configuration Wizard”.
6.       The first step is to choose a data source type and it is “Database” in our case.
7.       Hence, I leave the default option and proceed to the next page to choose a data connection.
8.       I get to create a new connection here.
9.       All I have to do is to locate the desired database file on the disk . . . and I’m done!
10.   In the last step, I’ll choose the data table that will supply data to the grid.
11.   The “Customers” table will do nicely in this lesson.
12.   I’ll specify a meaningful name for the DataSet . . .
13.   . . . and click Finish.
14.   The wizard has been completed . . . AND . . . as you can see, I have not only created the Data Source, but also bound it to the grid.
15.   We can see that the grid has automatically retrieved all the fields from the bound table and created columns for them.
16.   Since I don’t need to display all the columns, I’ll invoke the Grid’s Designer to remove some of them.
17.   I’ll switch to the columns page, select the columns I wish to remove, and delete them with a single click.
18.   You see that the corresponding field names are now bold, indicating that there are no columns bound to them.
19.   To create a column bound to a particular field, you can simply drag an item from the Fields ListBox, to the Columns ListBox.
20.   Now I’m done with column customization, so I’ll close the designer.
21.   Finally, I can run the application to see the result.
22.   A Grid Control, filled with data from the bound Data Table.


Enhanced by Zemanta