Improved support for Complex Type Parameters and FilterString (coming in v2010 vol 2)

DevExpress Data Blog
19 October 2010

In my previous post, we saw how report parameters and the FilterString editor had improved support for enum types. Let’s complicate matters a bit more by changing one of the enums to an actual class:

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

Building on the ReportDesignExtension introduced, we can now support complex types in report parameters:

ParamsComplex

The FilterString Editor was not left out:

FilterStringComplex

All of the previous steps required to support enums should be followed in order to support complex types. The only change is how we override the ReportDesignExtension:

  1: public class PersonReportExtension : ReportDesignExtension
  2: {
  3:     XPCollection<PayGrade> payGrades = new XPCollection<PayGrade>();
  4: 
  5:     public PersonReportExtension()
  6:     {
  7: 
  8:     }
  9: 
 10:     public override Type[] GetEditableDataTypes()
 11:     {
 12:         return new Type[] { typeof(PayGrade) };
 13:     }
 14: 
 15:     // repository item to show in params/filterstring
 16:     private RepositoryItem CreateRepositoryItem()
 17:     {
 18:         RepositoryItemLookUpEdit item = new RepositoryItemLookUpEdit();
 19:         item.NullText = "[Select Pay Grade]";
 20:         item.DataSource = payGrades;
 21:         item.DisplayMember = "Name";
 22:         item.ValueMember = "Oid";
 23: 
 24:         item.Columns.Add(new LookUpColumnInfo("Name"));
 25: 
 26:         item.Columns.Add(new LookUpColumnInfo("Low", "Low", 40, 
 27:             FormatType.Numeric, "c", true, HorzAlignment.Near));
 28: 
 29:         item.Columns.Add(new LookUpColumnInfo("High", "High", 40, 
 30:             FormatType.Numeric, "c", true, HorzAlignment.Near));
 31: 
 32:         return item;
 33:     }
 34: 
 35:     protected override RepositoryItem CreateRepositoryItem(DataColumnInfo dataColumnInfo, 
 36:                                                            Type dataType, XtraReport report)
 37:     {
 38:         return CreateRepositoryItem();
 39:     }
 40: 
 41:     protected override RepositoryItem CreateRepositoryItem(Parameter parameter, 
 42:                                                            Type dataType, XtraReport report)
 43:     {
 44:         return CreateRepositoryItem();
 45:     }
 46: 
 47:     public override void AddParameterTypes(IDictionary<Type, string> dictionary)
 48:     {
 49:         base.AddParameterTypes(dictionary);
 50:         dictionary.Add(typeof(Gender), "Person's Gender");
 51:         dictionary.Add(typeof(PayGrade), "Person's Pay");
 52:     }
 53: 
 54:     public override Type[] GetSerializableDataTypes()
 55:     {
 56:         return new Type[] { typeof(PayGrade) };
 57:     }
 58: 
 59:     // when serializing report params/filterstring data
 60:     protected override string SerializeData(object data, XtraReport report)
 61:     {
 62:         return ((XPObject)data).Oid.ToString();
 63:     }
 64: 
 65:     // for deserializing report params/filterstring data
 66:     protected override object DeserializeData(string value, Type destType, XtraReport report)
 67:     {
 68:         return payGrades.Session.GetObjectByKey(destType, Convert.ToInt32(value));
 69:     }
 70: }

While this kind of extensibility was previously possible, this solution is much more elegant and robust.

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

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

5 comment(s)
Markus Landwehr
Markus Landwehr

Hi,

the picture after the text "The FilterString Editor was not left out:" show's the FilterControl (i think that is the Version that will be included in v10.2) with the Item "Pay ... >" in the popup.

Can you tell something about how that can be archived an what function it has?

Thanks

Markus

26 November, 2010
Seth Juarez (DevExpress)
Seth Juarez (DevExpress)

In essence, the same kind of editor used when selecting the parameter value is now also available in the FilterString editor. Hope this helps!

25 January, 2011
Craig Farren
Craig Farren

This is exactly what I am looking for but I am having 1 slight issue with my implementation.

In my custom report extension class which inherits ReportDesignExtension I have set the repository item in the same way as in the example.

XPCollection<PayGrade> customers = new XPCollection<Customer>();

RepositoryItemLookUpEdit item = new RepositoryItemLookUpEdit();

item.NullText = "[Select Customer]";

item.DataSource = customers;

item.DisplayMember = "Name";

item.ValueMember = "Oid";

When I select this object as a type through the type field in the properties window I get the drop down with a list of all customers in the value field but when I select one I get this error.

"Invalid cast from 'System.Int32' to 'CustomerInfo'.

Any idea's what that is about? I think it has something to do with the custom lookupedit because if I don't set the valuemember it works fine.

1 August, 2011
Seth Juarez (DevExpress)
Seth Juarez (DevExpress)

Craig:

 Good question. This seems like it should work. I would submit a support question. Make sure you email me the Q ID so I can track it as well. Thanks for bringing it up!

1 August, 2011
Aravind Kesiraju X
Aravind Kesiraju X

Any luck with the last question in the most recent version of DevExpres ?

I have the same scenario and it says invalid cast when the ValueMember is specified. Although it works partially with the ValueMember is not specified.

9 July, 2014

Please login or register to post comments.