Creating Cross Tab Reports using the XtraReports Suite (WinForms-Visual Studio .NET)

Thinking Out Loud
28 March 2008

If you've had to create cross-tab reports with competing reporting tools in Visual Studio .NET...well, you know what a nightmare it can be. Thought all of you might find it useful to see step by step instructions on creating a cross-tab report with the XtraReports Suite v2008 vol 1. In this example, I'll focus on WinForms - in a subsequent blog post, I'll describe how you can accomplish the same for ASP.NET.

Before I continue - let me put on my marketing hat and say that the XtraReports Suite is available for $499.99 with full source code and $349.99 without source code. It's also included in our DXperience Subscription packages. Regardless of how you purchase it (standalone or as part of DXperience), XtraReports offers you full featured reporting for both WinForms and ASP.NET

Ok...onto the step-by-step cross-tab report tutorial. The first dozen or so steps are rather basic so if you get bored, jump to the Adding Fields section for the heart and guts of cross-tab report creation with the XtraReports Suite.

  1. Start Visual Studio (I know, this one is sort of a no brainer)
  2. Create a new Windows Application
  3. On the Project menu, select Add New Item…, or press Ctrl+Shift+A to invoke the Add New Item dialog.
  4. Choose XtraReport Class v8.1, and click Add.
  5. Open the Toolbox pane and then drag & drop the XRPivotGrid control from the DX: Reports.v8.1 toolbox tab onto the Detail band.

Binding Data

  1. Invoke the Smart Tag for the XRPivotGrid (for this, click the arrow icon located at the top-right corner of the XRPivotGrid control).
  2. In the Smart Tag, choose the Data Source property and click the Add Project Data Source link.
  3. Choose the Database type, click Next.
  4. Set the Data Connection to the nwind.mdb file. For this, click New Connection, set the Microsoft Access Database File (OLE DB) as the Data source, click Browse and locate the nwind.mdb file on your hard drive. Click Ok, then Next.
  5. Click No to leave data source file in its original location.
  6. Click Next.
  7. Choose the SalesPerson view, and click Finish. Now the XRPivotGrid is bound to the SalesPerson view (its Data Source is set to nwindDataSet1, Data Member to SalesPerson, Data Adapter to salesPersonTableAdapter).

Now onto the interesting stuff

  1. In the XRPivotGrid's Smart Tag, click the Run Designer… link.
  2. Click the Retrieve Fields button.
  3. Switch to the Layout section in the navigation bar on the left.
  4. Drag & drop the CategoryName and ProductName fields to the Row Fields area.
  5. Drag & drop the Country and SalesPerson fields to the Column Fields area.
  6. Drag & drop the Quantity and ExtendedPrice fields to the Data Items area.
  7. Click Apply.
  8. Close the editor.

The following is an image describing what you ought to see in design time

XtraReports Design Time

Preview the Cross-Tab Report

To preview a report, add this code to the Click event of a button.

private void button1_Click(object sender, EventArgs e) {    new XtraReport1().ShowPreview();}

Execute the application - the result should look like this: 

XtraReports - Cross Tab Report

Obviously, formatting the report to meet the needs of your customers is the next step - but we'll leave that for another day...Also, dont forget to read my post on using the XtraPrinting System to render your WinForms UI to paper - if using the XtraPivotGrid, you have some interesting options available to you so that you radically reduce the number of reports you'd otherwise be forced to manually generate.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.