Databinding and derived entities

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 01-Apr-2005 20:42:55   

Greetings, I have a derived entity class (based on the templates in the 3rd party) that has a custom readonly property (TotalPrice). I created a TotalPriceChanged event and a OnTotalPriceChanged sub to raise the event (as done in for the properties in the genrate code by LLBL's templates). One starnge symptom is that when I call OnTotalPriceChanged to trigger data-binding refersh it does NOT occur but if I call any of LLBL's generated Onxxx subs the UI does get refreshed correctly. I had to use a hack where in the OnTotalPriceChanged I would actually call any of the other Onxx subs..

Is there anything special that I have to do in my derived entity classes so that my custom properties data-binding would behave as the other properties in the LLBL generated class

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 02-Apr-2005 12:47:58   

That's very strange... it should work.

though.. what is the binding scenario you're in: a grid or a textbox style binding scenario? (this makes a huge difference)

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 02-Apr-2005 21:30:40   

my senario is of simple binding (text-box and the likes...). The funny thing is that even if I call the Onxx sub from the base entity class (in my custom property OnxxChanged sub to force a change notification) that also does NOT work. BUT, if I actually change any of the base entity's properties (I do that as a hack in my custom property's OnxxChanged sub) the UI does refresh correctly...

Notice that all this is I said for simple TextBox binding

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Apr-2005 11:30:07   

Is the TotalPrice a readonly property by any chance? If so, could you change it to a read/write property (and simply do nothing in the setter)

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 03-Apr-2005 16:07:00   

IT IS a readonly property and I will try that and let you know...

BTW, I don't face this problem in the grid (using DevExpress grid) and all my custom properties refresh OK...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Apr-2005 16:20:32   

omar wrote:

IT IS a readonly property and I will try that and let you know...

BTW, I don't face this problem in the grid (using DevExpress grid) and all my custom properties refresh OK...

A grid uses a different kind of databinding (Complex binding as it is called in .NET). Simple databinding (i.e. control binds to property) uses the ..Changed event handlers, grids use the property descriptors and ListChanged events.

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 03-Apr-2005 18:13:04   

thats really strange behaviour

Private m_strTransferByName As String
Public Property StrTransferByName() As String
    Get
        Return m_strTransferByName
    End Get
    Set(ByVal Value As String)

    End Set
End Property


Public Event StrTransferByNameChanged As EventHandler
Protected Sub OnStrTransferByNameChanged()
    RaiseEvent StrTransferByNameChanged(Me, New EventArgs)
End Sub

Private Sub UpdateStrTransferByName()

    If Me.StrTransferBy = String.Empty Then
        m_strTransferByName = String.Empty
    Else
        Dim x As HREmployee = HREmployee.FetchObject(Me.StrTransferBy)
        If x Is Nothing Then
            m_strTransferByName = String.Empty
        Else
            m_strTransferByName = x.StrFullNameEn
        End If
    End If

    OnStrTransferByNameChanged()

End Sub

I call UpdateStrTransferByName() from the changed event of one of my base entity properties ((StrTransferBy). What I noticed in the UI is that when I change the (StrTransferBy) property the (StrTransferByName) property does NOT get updated in the UI UNTIL I change ANY other property in the UI. Thats where I got the idea of the hack of adding an extra line of code in the (OnStrTransferByNameChanged) where I CHANGE the value of some random property

 Me.DtmDateEnteredWS = Date.Now

so as to properly trigger the UI refresh

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Apr-2005 10:51:37   

ANd when you do:


Private m_strTransferByName As String
Public Property StrTransferByName() As String
    Get
        Return m_strTransferByName
    End Get
    Set(ByVal Value As String)
        m_strTransferByName = Value
        OnStrTransferByNameChanged()
    End Set
End Property


Public Event StrTransferByNameChanged As EventHandler
Protected Sub OnStrTransferByNameChanged()
    RaiseEvent StrTransferByNameChanged(Me, New EventArgs)
End Sub

Private Sub UpdateStrTransferByName()

    If Me.StrTransferBy = String.Empty Then
        Me.StrTransferByName = String.Empty
    Else
        Dim x As HREmployee = HREmployee.FetchObject(Me.StrTransferBy)
        If x Is Nothing Then
            Me.StrTransferByName = String.Empty
        Else
            Me.StrTransferByName = x.StrFullNameEn
        End If
    End If
End Sub

?

The thing is that a property is set, otherwise it's not. Though it should work what you wrote, IMHO, although I'd call UpdateStrTransferByName from the property, not from the On..Changed handler.

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 04-Apr-2005 19:32:40   

although I'd call UpdateStrTransferByName from the property, not from the On..Changed handler.

I would like to do that my self BUT the problem is that my class is a Derived Entity class and the new property only exists in the derived entity class and NOT in the base entity class.

I don't know if there is a better design pattern for this...