An Even Easier Way to Create Cross Tab Reports...

02 April 2008

***FLASH*** The LA Times reports that Pau Gasol is set to return to the Lakers tonight.

OK - with that, onto business...

Last week, I wrote the following blog post about creating cross tab reports with the XtraReports Suite. In a previous post, I discussed how much I hate creating reports and the importance of bringing one's UI to the printed page to radically reduce the number of reports one would otherwise have to create manually. If you have not read these posts, you might want to take a quick look now before proceeding...

As you know, XtraReports is an industrial strength reporting solution and creating cross tab reports with it is a piece of cake...In my last blog post, I gave you step by step instructions on creating a cross tab report with the XtraReports Suite. With this post, I want to show you how to use the XtraPivotGrid and the XtraPrinting System together to replicate what we did with XtraReports.

Why you ask - why bother describing the latter when I already showed you how to do the former? For me, the answer to this question is quite simple. If I can deliver an intuitive UI which gives users the ability to mine and dissect data - AND - allow them to render what they see on screen to paper, then I've made my application more usable, improved my end-user's experience, and reduced my workload.

Onto the demo...

Our first step is to create a form that contains the XtraPivotGrid within

  1. Start Visual Studio
  2. Create a new Windows Application
  3. Open the Toolbox pane and then drag & drop the PivotGridControl from the DX: Win.v8.1 toolbox tab onto the Form1.

Binding Data

  1. Invoke the Smart Tag for the PivotGridControl (select the control and then click the arrow icon in its top-right corner).
  2. In the Smart Tag, select the Choose 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, which is used in XtraReports demos. 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 drive. Click Ok, then Next.
  5. Click No to leave data source at its original location. Click Next.
  6. Choose the SalesPerson view, and click Finish. Now the PivotGridControl is bound to the SalesPerson view (its Data Source is set to nwindDataSet1).

Adding Fields

  1. In the PivotGridControl'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. Close the editor.

What you should now be able to see is the following

XtraPivotGrid Design Time

And here's what you should see at runtime...

XtraPivotGrid at Runtime 

Rendering to Paper

To invoke the Print Preview of a Pivot Grid, add this code to the Click event of a button on your form:

private void button1_Click(object sender, EventArgs e) {pivotGridControl1.ShowPrintPreview();}

Run the application - press the button with the event handler above and you should see something this:

Printing the XtraPivotGrid

Of course, your user's will be able to drill-in and out as needed with your UI. They will be in control and once they've created the appropriate snapshot, the XtraPrinting System will take care of the rendering.

All of these products are included in our DXperience package - making it one heck of a value if I do say so myself. Pound for pound, Im convinced nothing comes close (of course Im biased, but you can always Download, Compare, then Decide for yourself).


12 comment(s)
Mohsen Benkhellat

It would have been the perfect report generator if it supported auto-referenced hierarchies :-(

On a side note, giving access to the generated report source to let users who want to save it or even modify it with report designer would be a nice feature.


2 April, 2008
Ray Navasarkian (DevExpress)

It wasn't meant to be the perfect report generator - it's a UI rendering has to be practical.

I personally disagree the notion that the user ought to be able to save the report for further modification within a "designer." The whole point of my posts of late is that based on my experience, users dont know how to use designers. Your users might be different than mine, but I've talked to enough people to know my experience is not all that unique.

The whole point of this is to render the UI...This isnt there to replace a reporting tool - its to augment it.

2 April, 2008

That's exactly what I thought when I saw your first blog article, why not just go from the XPG direct to the print preview?

Now what I'd like to see is a parameter on the print preview to use a RibbonPrintPreview instead - it's sooo much more hip! :)

2 April, 2008
Mohsen Benkhellat

By feature I meant optional so that if a user wants it he can use it otherwise he just ignores it


2 April, 2008
Ray Navasarkian (DevExpress)

As I mentioned previously Mohsen - if your objective is to give the end-user access to runtime report modification to that degree, then you ought to use XtraReports....

3 April, 2008

Sorry to chime in from left field here, but I was curious about the printed output? For example, how something looks on screen would likely be different than on paper (PDF). You might want headers, footers, margins, limits on the number columns etc on the printed version but clearly not on the online version or in an Excel export. The example you display here is rather unsightly on paper even if it is serviceable online.

3 April, 2008
Ray Navasarkian (DevExpress)

Hey Thomas - I take it you have not played with our demos? When you get the chance, crank up demo center and start the XtraGrid Main Demo. Once you start the demo, use the NavBar on the left and navigate down to the Appearance Group. Once there, select Style Conditions. At this point, move up to the Print And Export To... menu item and select Print Preview.

You will see that this particular report is rendered with the style conditions displayed within the grid.

As far as your other question - setting headers/footers/margins - easy enough...for headers/footers, press the 8th toolbar button from the left in the Print Preview window. You should see a familiar MS Word Style dialog for that purpose.

Finally as far as "limits on the number of columns..." - this is another way in which you can shine...what if you created a way in which the user could save "data views" and easily recall them for future use prior to printing. The simplest way one could do it is with a combo box on a toolbar...User modifies the visual control as they see fit (removing columns that they dont want to see in the report - summarizing on specific columns, grouping/sorting as needed) then saves that View for later use. Next time they need to "run" a report they simply call up the view from the combobox and you are on your way to kicking some butt.

I know - I know...for the reporting purist, what I describe is blasphemy...but again, eliminating fixed reports wherever possible is always mission one for me :-)

3 April, 2008

What about show the filter selected in the pivot, in the report header

13 April, 2008
Dr. Holger Flick


features like these definitely convinced me that DevExpress is the right solution for WinForm controls that need "easy" reporting "now and then".  

I think that DevExpress will never reach the grain of detail that professional report engines do, but I think that is not needed for 99% of my applications and thus I am happy being able to "convert" my grids on screen to paper with very little work. Furthermore, it has to be said that it beats a lot of pure reporting solutions.

20 April, 2008
Windows Forms

Cross-Tab reports can be a great way to show summaries of data. What is a Cross-Tab report? As Oliver's

25 April, 2008
Thinking Out Loud

First and foremost, if you're using our WinForms (Windows Forms if you prefer) controls already,

2 July, 2008
Big in Japan

先週、CEOのレイが弊社開発のWindowsフォーム専用製品ラインについてブログを書きました。以下がその翻訳ですのでお読みください。 弊社の価値提案 – 弊社製品から得られるものと他社製品との比較

9 July, 2008

Please login or register to post comments.