Improved Parameter Support for Reports

03 August 2012

There were a number of gems recently added to our already fabulous reporting suite. One of the interesting ones was improved parameter support. Previously one could only create and expose parameters over integral types. A great example is filtering a report by a CategoryId. Before you would only be able to create a parameter of type int and have users type in numbers rather than category names. With our improved parameters dialog there are now additional options to choose from:

New Report Parameter Dialog

Once you check the “Supports the collection of standard values” checkbox you now have the ability to create a set of values that the parameter can take. These can be created either by a collection of static values or binding to a set of dynamic values.

Static Values

This option simply lets you define the set of available options manually.

Static Values in Report Parameter Dialog

The interface allows for the entry of the actual value passed as the parameter along with a description of what will be displayed.

Dynamic Values

Using dynamic values allows for binding to a set of key/value pairs to be displayed.

Dynamic Values in Report Parameter Dialog

In this case we need to set the source of the data, how the data is retrieved, as well as the value and display members. At runtime both methodologies yield the following result:

Report Parameter Values in Report Preview

Now your users can choose from an intelligible list of options that are better suited to your user while dealing with the pieces of data (like an id number) your system likes in the background.

Wait, there’s more

The next question I will invariably get is this:

“But Seth, our reports are not bound to datasets with table adapters! Can I still have dynamic parameters?”

Of course! In this particular case the best course of action is to use a Static Values list. When doing the intial setup you can place any value to start. We can then take advantage of the ParametersRequestBeforeShow event to populate the static value list as we see fit:

private void ProductReport_ParametersRequestBeforeShow(object sender, ParametersRequestEventArgs e)
{
    if (CategoryId.LookUpSettings is StaticListLookUpSettings)
    {
        var lookup = (StaticListLookUpSettings)CategoryId.LookUpSettings;
        lookup.LookUpValues.Clear();
        lookup.LookUpValues.Add(
            new LookUpValue { Value = 1, Description = "AAA" }
        );

        lookup.LookUpValues.Add(
            new LookUpValue { Value = 2, Description = "BBB" }
        );

        lookup.LookUpValues.Add(
            new LookUpValue { Value = 3, Description = "CCC" }
        );
    }
}

This code is deliberately simple to show the possibilities. Here I am simply hand coding the available parameter options directly into the method. One could imagine a scenario where we make a service/database/foo call to retrieve the key/value pairs to subsequently populate the list. Running the previous code will result in the following:

Report Parameter Custom Values in Report Preview

This new addition to our reporting suite will definitely simplify our ability to help our end users consume dynamic reports.

As always, if there are any comments and/or questions, feel free to get a hold of me!

Seth Juarez
Email: sethj@devexpress.com
Twitter: @SethJuarez

Want The Best Reporting Tool Ever?

Get The No-Compromise Reporting Tool for WinForms, ASP.NET, Silverlight and WPF! - Native integration with DevExpress WinForms and ASP.NET Controls, unequalled design-time productivity, industrial-grade features. Try a fully-functional version of DXperience for free now: http://www.devexpress.com/Downloads/NET/

Let us know what you think of our Reporting Suite by rating it in the VS Gallery!

Follow SethJuarez on Twitter

5 comment(s)
James S K Makumbi

You have no idea how often the integer thing stymied me! Thank goodness it was sorted. Now I can REALLY go to town on filtering.

3 August, 2012
James Zhong

Thanks for your improved XtraReports designer!

6 August, 2012
Marcus Gardner

Nice work.  Effort put into things that will help in real world situations is always appreciated.

29 August, 2012
Michael Proctor [DX-Squad]

This is a great improvement, I didn't use the built in filtering features for this reason. Good work guys.

2 September, 2012
Marcello Rutter (AKA Mr. Dev)

Dear Seth, great job!

It would be very very interesting to see the parameters management implemented as a standalone control/component. The report parameters model is usefull in many many other different scenarios.

Thank you.

Marcello

24 October, 2012

Please login or register to post comments.