Binding to an object with properties that are not simple types

Binding to an object with properties that are not simple types

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


AndrewCr posted on Friday, August 18, 2006

I’ve got a business object with some properties that are conceptually a composite type.  For example, a price expressed as a number and a currency type, or a dimension expressed as a number and a unit.  (60 pesos, 8 furlongs, etc)

 

To me these seem like natural candidates to be stored as structures – they’re small, they usually need to be passed together, they aren’t meaningful on their own.  But, if I declare a property on my business object to be a structure, it screws up the way binding works – a grid row only adds one column for the property, and when I drag-and-drop from the Data Sources window to a user control (like we learned in the book :)  ) it won’t let me drag the structure properties.  If I try to change the binding on an existing control, it lets me pick the property, but there’s no where to manually add the syntax to specify which structure element I want.

 

Has anyone else run into this type of problem?  What are people’s thoughts about the trade-offs between designing a business object that binds easily vs. one that’s coherent and easy-to-understand for human consumers?

 

Thanks,

  Andy

 

ajj3085 replied on Friday, August 18, 2006

Hmm, if you're using the parent BO in a grid, you may have to create your own DataGridViewColumn /Cell class.  At least, that's one way to handle this.  Another would be to encapsulate the Price and expose the two properties as if they were simply part of your BO.   There's a design pattern describing that... but I don't recall it off the top of my head.

HTH
Andy

Copyright (c) Marimer LLC