CSLA 1.x - wishing my ERO could mimic IList

CSLA 1.x - wishing my ERO could mimic IList

Old forum URL: forums.lhotka.net/forums/t/1336.aspx


Q Johnson posted on Tuesday, September 26, 2006

I am building a fairly plain and simple car registration system.

When the user is on the screen on which they edit all the vehicle/owner/title data, they often want to print either a certificate of registration or a certificate of title.

I'm using the DevExpress xtraReport tool here and have built a report that should work just fine.  And of course the tool is capable of binding to business objects which is the major reason I'm using it.  Sounds good so far, eh?

My problem is that the report tool can only bind to objects that implement IList (which doesn't seem such a harsh requirement), but when users are editing my Vehicle object, it's an ERO - which, of course, doesn't implement IList.

[If you don't use an IList-capable report tool, just imagine that you want to display your ERO's properties in one row of a datagrid in which case you run into exactly the same obstacle I face here.]

I guess I can build a child collection (or perhaps better, a single-member R-O Collection object) to clone my ERO's properties just for the report.  But this seems quite the kludge, doesn't it?!!

Isn't there a more elegant way to solve this?  For example, could I make my Vehicle ERO implement IList well enough for the report to bind to its properties?  And, if so, how?  And if not, are there other appealing options that I'm too dense to see yet?

Thanks in advance,

RockfordLhotka replied on Tuesday, September 26, 2006

Perhaps you can do what Microsoft does in .NET 2.0, and just put your object into a list?

If you bind a single object in .NET 2.0, they automatically create a list object, put your object into it, and use the list as the data source to the controls. This is done by the bindingsource control, but you could do it yourself too.

Just put your object into any collection type that implements IList (an ArrayList perhaps), and away you go.

If you want (need) to get fancy, you might need to create an equivalent to .NET 2.0's BindingList<T> - though obviously without generics - but it is something you could do if you need the IBindingList semantics.

Q Johnson replied on Wednesday, September 27, 2006

RockfordLhotka:

Just put your object into any collection type that implements IList (an ArrayList perhaps), and away you go.

I used an ArrayList.  It was simple as can be and worked perfectly on the first try.  Thanks for the great tip!

For other new DevExpress xtraReport users who may be lurking - I declared the ArrayList Public in my xtraReport file (sure I could have written a property set procedure instead).  Then in the button click code from my form I just (1)create the local ArrayList, (2).Add my BO to it, (3)create the local report object, (4) assign my local ArrayList to the Report's one, and (5)call ShowPreview.

Of course creating the bound controls on the report will be a task of varying difficulty in different circumstances.  But in my case, I had built the report with Access (having built a query for it) and simply imported it into a new xtraReport.  I never had to write a single line of code to handle the binding.  This feels pretty efficient to me!!

Thanks again, Rocky.

 

Copyright (c) Marimer LLC