I like the XtraPivotGrid. The XtraPivotGrid lets users create crosstab views of data that permit alternative ways to look at the same data. More than that I like the XtraPivotGrid for its end user composability. It is one of those controls that naturally lend itself to end user customization post delivery. By dragging and dropping data elements to row, column, data or filter areas a user can completely change the layout of the data and look at the data from any perspective that makes sense to the user. For the developer the XtraPivotGrid means that the amount of time spent at design time can be reduced; bind the XtraPivotGrid to a data source (or OLAP) source and let the user tinker with the appearance.
If you combine the end user composability factor with built in printing capabilities a user can take a code-light XtraPivotGrid form and turn it into an ad hoc reporting engine. All of this capability is built into the XtraPivotGrid. As a developer you just need to obtain your copy of DXperience (or the XtraPivotGrid) an you get these features and your customers can have access to the power and flexibility without necessitating writing a ton of code on your part. the following steps walk you through creating a WinForms application with an XtraPivotGrid and turn it into an ad hoc reporting tool with a minimum of effort.
To create the demo (shown in Figure 1) follow these steps:
1. Create a WinForms application in Visual Studio 2010
2. Drag a DevExpress RibbonControl onto the form. (This will be used to initiate printing)
3. Use the RibbonControl designer to add a BarButtonItem to a RibbonPageGroup (see Figure 2)
4. Switch to the BarButtonItem’s event’s view and implement the ItemClick event. (See Listing 1 for the code for the ItemClick event)
5. Drag a PivotGridControl to the form and change the Dock style to Fill.
6. From the PivotGridControl’s smart tags menu select Choose Data Source, and click Add Project Data Source
7. Configure the Northwind database’s Products table
8. Add the code to the ItemClick event as show in Listing 1
9. Run the demo
Figure 1 shows the runtime view and Figure 3 shows the design time view. Notice that in this demo we didn’t even set the columns to any of teh areas in the PivotGridControl. We will let the end user decide where to display the data elements at runtime.
figure 1: The runtime view prior to setting the data elements to the desired areas of the XtraPivotGrid.
Figure 2: Add a BarButtonItem to the RibbonControl and implement the ItemClick event for the print action.
Figure 3: The design time view of the demo.
Listing 1: the code-behind for the ItemClick event.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'NorthwindDataSet.Products' table.
'You can move, or remove it, as needed.
Me.ProductsTableAdapter.Fill(Me.NorthwindDataSet.Products)
End Sub
Private Sub BarButtonItem1_ItemClick(ByVal sender As System.Object,
ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
PivotGridControl1.OptionsPrint.VerticalContentSplitting =
DevExpress.XtraPrinting.VerticalContentSplitting.Smart
PivotGridControl1.OptionsPrint.PageSettings.Landscape = True
PivotGridControl1.Print()
End Sub
End Class
Clearly the user will want to move data elements around and configure a layout that tells them a user story about the data. Follow these steps to configure one view of the data.
1. In this order drag the CategoryID to the area that reads Drop Row Fields Here
2. Drag the SupplierID next to the CategoryID
3. Drag the ProductName next to the SupplierID
4. Drag and drop the Units In Stock, Unit Price and Units On Order fields to the area that reads Drop Data Items
5. Collapse a few of the categories so you can see the totals and grand totals row—see Figure 4
6. Click the print button
Figure 5 shows the first page of the printed report. For an ad hoc report this conveys the data desired in the layout desired and it looks pretty good for a no-code solution. If you want more control over the “report” then consider switching to XtraReports. However, a lot of time users need ad hoc reports as often as they need pre-determined reports, and the built in printing capabilities make ad hoc reporting a reality with little or no effort from you.
Figure 4: The view after following steps 1 through 6 above.
Figure 5: An ad hoc report fully created by the end user.
If you haven’t used the XtraPivotGrid before there are a few features I’d like to point out before we wrap up. Click any of the field buttons and a filter tag menu pops up. This feature let’s the user pick the data results for that field, including all or individual fields. Click field buttons in the row area to change the sort order of the that row. Right-click the a field button to display a context menu. the context menu let’s the user Reload data, hide, change the order, show the field list (to retrieve hidden field’s), and show a PivotGrid Prefilter dialog that enables the end user to build custom data filters visually (see Figure 6).
Figure 6: Use the PivotGrid Prefilter at runtime to define custom data filters. (In the example only categories greater than 5 are shown).
After you apply a filter the filter is shown at the bottom of the XtraPivotGrid and it can be disabled and re-enabled or deleted by the end user (see Figure 7).
Figure 7: Enable, disable, or delete prefilters defined by the end user here.