Blogs

DevExpress Reporting Blog

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

     

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

Published Oct 18 2010, 12:47 PM by Seth Juarez (DevExpress)
Bookmark and Share

Comments

 

Simon from ActiveDataTools.com said:

Like this a lot.

October 18, 2010 7:13 PM
 

Steve Sharkey said:

Very nice

October 19, 2010 2:48 AM
 

AndyYin said:

Very good.

October 19, 2010 7:51 AM
 

Anuraag Sanwal said:

cool

really should be very useful & flexible

gr8 work done guys !

October 19, 2010 11:39 AM
 

Nate Laff said:

XAF compatible?

October 19, 2010 3:15 PM
 

Seth Juarez (DevExpress) said:

October 19, 2010 3:28 PM
 

Nate Laff said:

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

October 19, 2010 5:05 PM
 

Dennis (DevExpress Support) said:

@Nate: Yes, it does!

October 19, 2010 5:25 PM
 

Stefan Haug said:

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

January 25, 2011 2:35 PM
 

Seth Juarez (DevExpress) said:

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!

January 25, 2011 3:09 PM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.