Creating a "virtual," or fake, property

  • Thread starter Thread starter Colin Young
  • Start date Start date
C

Colin Young

Is there a way I could create an imaginary property on one of my objects?

e.g. I would like to be able to call MyObject.Unbound1, MyObject.Unbound2,
MyObject.Unbound3, ... without needing to actually define Unbound1,
Unbound2, Unbound3, ...

The reason I need to do this is because I have a customised datagrid that
displays a collection of a custom business object and has some calculated
columns. I need to reuse some of the columns in the calculated columns (e.g.
I am displaying Cost and Quantity and I need to also display Cost *
Quantity, but in order to do that I need to set the MappingName to a valid
property of my object, but I've already displayed all the properties of my
object in the grid).

My other option is to add n 'Unboundn' properties to my object, where 'n' is
a suitable large number that is hopefully bigger than than the number of
additional columns the UI tier might wish to display.

Any ideas?

Thanks

Colin
 
Colin,

Instead of creating "imaginary" properties, have the object (or another
object that the grid is bound to) implement the ICustomTypeDescriptor
interface. It will allow you to specify any number of properties you want,
and then be called when it needs to get the value of those properties
(through a call to GetPropertyOwner).

Then, all you have to do is bind to the implementation of
ICustomTypeDescriptor.

Hope this helps.
 
I think that will do what I want. As far as I'm concerned, that is creating
"imaginary" properties (at least for my specific needs).

Thanks

Colin

Nicholas Paldino said:
Colin,

Instead of creating "imaginary" properties, have the object (or another
object that the grid is bound to) implement the ICustomTypeDescriptor
interface. It will allow you to specify any number of properties you want,
and then be called when it needs to get the value of those properties
(through a call to GetPropertyOwner).

Then, all you have to do is bind to the implementation of
ICustomTypeDescriptor.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Colin Young said:
Is there a way I could create an imaginary property on one of my objects?

e.g. I would like to be able to call MyObject.Unbound1, MyObject.Unbound2,
MyObject.Unbound3, ... without needing to actually define Unbound1,
Unbound2, Unbound3, ...

The reason I need to do this is because I have a customised datagrid that
displays a collection of a custom business object and has some calculated
columns. I need to reuse some of the columns in the calculated columns (e.g.
I am displaying Cost and Quantity and I need to also display Cost *
Quantity, but in order to do that I need to set the MappingName to a valid
property of my object, but I've already displayed all the properties of my
object in the grid).

My other option is to add n 'Unboundn' properties to my object, where
'n'
is
a suitable large number that is hopefully bigger than than the number of
additional columns the UI tier might wish to display.

Any ideas?

Thanks

Colin
 
Back
Top