Improved support for enums in report parameters and FilterString (coming in v2010 vol 2)

DevExpress Data Blog
18 October 2010

One of the interesting features of our reporting tools is the ability to manipulate report parameters at run-time and at design-time (for both the developer AND the client). A neat little feature that is coming up in v2010 vol 2 is support for custom enumerations in report parameters.

Consider the following type definition as the data source for a report:

  1: public enum Gender
  2: {
  3:     Male,
  4:     Female
  5: }
  6: 
  7: public enum PayGrade
  8: {
  9:     Miniscule,
 10:     Decent,
 11:     Good,
 12:     Billionaire
 13: }
 14: 
 15: public class Person : XPObject
 16: {
 17:     public string Name { get; set; }
 18:     public Gender Gender { get; set; }
 19:     public DateTime BirthDate { get; set; }
 20:     public PayGrade Pay { get; set; }
 21: }

Parameter Property Editors

Now when adding parameters, the combo box for the value of the particular enum contains the actual values available in the same. This feature is also available in the report’s Filter String Editor:

FilterString Editor Window

Here’s how to do it:

Step 1: Create a custom report design extension:

  1: public class PersonReportExtension : ReportDesignExtension
  2: {
  3:     public PersonReportExtension()
  4:     {
  5:             
  6:     }
  7: 
  8:     public override void AddParameterTypes(IDictionary<Type, string> dictionary)
  9:     {
 10:         base.AddParameterTypes(dictionary);
 11:         dictionary.Add(typeof(Gender), "Person's Gender");
 12:         dictionary.Add(typeof(PayGrade), "Person's Pay");
 13:     }
 14: }

Step 2: Register the design extension:

  1: ReportDesignExtension
  2:     .RegisterExtension(new PersonReportExtension(), "PersonEnums");

Step 3: Set the appropriate data source for a new report:

  1: XPCollection<Person> source = new XPCollection<Person>();
  2: report = new XtraReport();
  3: report.DataSource = source;

Step 4: Associate a report with the custom extension:

  1: ReportDesignExtension
  2:     .AssociateReportWithExtension(report, "PersonEnums");

Calling report.ShowDesignerDialog() will then have all of the enum associated goodness.

As always, if you have any questions and/or comments feel free to let me know.

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

Showcase Your Apps on DevExpress.com

Highlight your business app and share your development experiences with the DevExpress community. To include your app in our upcoming App Showcase, please forward an application screenshot to clientservices@devexpress.com and tell us which DevExpress products you currently use within your organization.
Sigol
Sigol

Like this a lot.

18 October 2010
Steve Sharkey
Steve Sharkey

Very nice

19 October 2010
AndyYin
AndyYin

Very good.

19 October 2010
Anuraag Sanwal
Anuraag Sanwal

cool

really should be very useful & flexible

gr8 work done guys !

19 October 2010
Nate Laff
Nate Laff

XAF compatible?

19 October 2010
Nate Laff
Nate Laff

So, with XAF you don't even need to register the ReportDesignExtension then? just does it automatically?

19 October 2010
Dennis (DevExpress)
Dennis (DevExpress)

@Nate: Yes, it does!

19 October 2010
Stefan Haug
Stefan Haug

How does this mix with localization? Eg. instead of Male and Female localized words are displayed?

25 January 2011
Seth Juarez (DevExpress)
Seth Juarez (DevExpress)

In that case, I would look at this: community.devexpress.com/.../improved-support-for-complex-type-parameters-and-filterstring-coming-in-v2010-vol-2.aspx to do something a bit more complex. Let me know if this helps!

25 January 2011
Dennis Felix
Dennis Felix

Is it possible to get these types in the query editor?

6 September 2017
CRM-61bc2f57-b4ce-4cef-95eb-76160bdb9eb1
Mary

Hello Seth,

You have shown us how to accomplish this in end-user design time. Can you show how to accomplish this in Visual Studio design time? Thanks in advance

28 April 2021

Please login or register to post comments.