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

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.

12 comment(s)
RAUL TORTIMA

Fantastic!

29 March, 2008
DevInfox

I have a question. How can you run this report base on the filter data of a grid?

29 March, 2008
Alex Hoffman

Many thanks for posting this.  My focus is on other areas of the product suite, so I am unaware of great features such as this.

One issue, following your instructions using VS2008 with 8.1 - when I press the Preview tab, I get a serialization error (capture.alh.sent.com/img-03-30-2008-09-49-03%20AM.png).  When I then press the HTML view, VS crashes.

29 March, 2008
Alan (DevExpress)

Alex,

We are sorry, this is a known issue, which will be fixed in the next minor update to the XtraReports Suite (www.devexpress.com/issue=B30480).

Note that to avoid this problem, you need to rebuild your application before previewing a report at design time.

30 March, 2008
Stanislav Seltser

i would like to have hierarchies expanded downward instead of sideways. is this possible?

1 April, 2008
Thinking Out Loud

***FLASH*** The LA Times reports that Pau Gasol is set to return to the Lakers. OK - with that, onto

2 April, 2008
Ray Navasarkian (DevExpress)

Stanislav - not sure I know exactly what you want to do so write to support and layout your exact requirements and they'll follow up...thanks

2 April, 2008
Stanislav

Ray, i can send you comparative pictures of

Excel pivot table, XtraReports Suite  and the actual layout i need via email. posting pictures in this forum does not seem to be possible.

please send your email to me and i will reply

my email is stanislov.seltser@sungard.com

2 April, 2008
Ray Navasarkian (DevExpress)

Please send your mail to support@devexpress.com and let the guys know what they need and they'll follow up

2 April, 2008
Stanislav

do you have a pointer (video, or presentation) on how to create pivot table report with pivot component?

i had tried creating a form with VS2005 and drag PivotGrid control over there. i had connected my olap data source and able to retrive fields in DevExpress Designer  but the design pivot report is very unclear to me.

2 April, 2008
Arcoda srl

Alan, can you help me? I had an episode of crash in VS2008, as Alex (?)

I opened a topic in the forum:

community.devexpress.com/.../69801.aspx

The update also solves my problem?

Screenshot:

www.postimage.org/image.php

11 October, 2008
Alan (DevExpress)

ArcoDa,

I've answered you in this thread (community.devexpress.com/.../69801.aspx).

Does this help you?

14 October, 2008

Please login or register to post comments.