views:

72

answers:

1

I've got some classes that have properties like this, and they work perfectly because they are very normal:

    Public Overridable Property CustomerLastName() As String
        Get
            Return m_CustomerLastName.Value
        End Get
        Set(ByVal Value As String)
            m_CustomerLastName.Value = Value
        End Set
    End Property

I want to change them to work like this (and don't worry about what IField is, suffice it to say it represents a field in a table):

    Public Overridable Readonly Property CustomerLastName() As IField
        Get
            Return m_CustomerLastName
        End Get
    End Property

That way, you could do Customer.CustomerLastName.PreviousValue, or Customer.CustomerLastName.IsDirty, etc.

But that doesn't bind correctly. Understandable, since databinding is supposed to be a two-way thing, and there's reflection involved, etc.

Of course it can still be a two-way street, I just need to be able to say, "Hey DataBinding! Look over here!"

So. What do I do here?

Note: Right now, all I'm trying to do is DataBind to a GridView for display purposes. But I want this to be flexible.

A: 

(Update re edit) If it is just for display purposes, you can probably just set the ToString() on the class that implements IField.


(original)

No - 2-way data binding wants either INotifyPropertyChanged, or an CustomerLastNameChanged event. You can shim this into a custom model by implementing ICustomTypeDescriptor or TypeDescriptionProvider, but then you need to write your own PropertyDescriptor implementation.

Re IsDirty - that is ShouldSerializeValue in PropertyDescriptor terms.

Marc Gravell