Custom Properties in Extended Entity

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 19-May-2005 20:38:57   

Greetings Frans,

This is not a new issue as I have raised this problem with you before. Now it’s becoming a real pain and I wish we could find a solution for it. Scenario: 1- ICTransfer class inherits the ICTransferEntity class (using a customized version of the extended entity templates)

2- I define a new property (StrTransferByName) in the (ICTransfer) class as follows:


    Private m_strTransferByName As String
    Public Readonly Property StrTransferByName() As String
        Get
            Return m_strTransferByName
        End Get
    End Property

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

3- I override the (OnStrTransferByChanged) routine from the (ICTransferEntity) class to update the (StrTransferByName) property as follows

    
    Protected Overrides Sub OnStrTransferByChanged()

        UpdateStrTransferByName()

        MyBase.OnStrTransferByChanged()

    End Sub

4- the (UpdateStrTransferByName) routine as follows

     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
            OnStrTransferByNameChanged()
        End If

    End Sub

5- in the UI form (WinForms) I bind the property (StrTransferBy) to a combo-box and the property (StrTransferByName) to areadonly textbox

6- what I expect to happen is that when I choose an entry from the (StrTransferBy) combobox, the (StrTransferByName) textbox would be updated by WinForms data-binding to reflect the new (StrTransferByName) value.

As I debug the code, all code works fine and the custom property DOES get its new value; but the data-binding does NOT update it in the UI. I did a small trick where I added one line in the (OnStrTransferByNameChanged) routine that purposely changes the value of some arbitrary property of the underlying (ICTransferEntity) class:


    Protected Sub OnStrTransferByNameChanged()
        RaiseEvent StrTransferByNameChanged(Me, New EventArgs)
        Me.DtmDateEnteredWS = Date.Now  'Databinding hack !!
    End Sub

then the databinding magic works beautifully. Needless to say, this sort of hack caused me all sorts of problems (like making the entity Dirty while it should NOT be). Now, I am implementing the update in the UI at the (validated) event of the combo-box. This is working fine but I really want to get to the bottom of this problem. Why does the underlying Entity class properties work with simple binding while the extended entity properties don't?!! The only difference in code I see between both is that the entity class properties changes their values using the (SetNewFieldValue) function which is something I can't do in the extended entity class since the new custom properties in the extended entity do not have field indexes.

How about it Frans, am I missing something here. I tried making my custom properties Read/Write without a difference. I tried using standard WinForms controls as well as my 3rd party controls with same results. cry

P.S: I thought this could be worth noting. When using the generated DAL DLL for design time databinding, the factory used would be that of the EntityClass. I would then (manually) change the factory being used for the entity collection from that of the EntityClass to that of BL Class (the extended entity class). This way my UI controls would see any custom properties I have added in the derived entity class. I do that change in two areas; the windows generated code in the code-behind of the secreen and also in the form's XML resource file..

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-May-2005 12:09:34   

Is the event StrTransferByNameChanged fired or not? If you bind a handler to that event, is it fired? (not with your hack, but with the normal code you initially wrote). Is the StrTransferByName value showing up in the textbox?

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 20-May-2005 12:23:02   

I tried your suggestion. In the UI form, I added a handler to the (StrTransferByNameChanged) event and it worked OK. When I changed the (StrTransferById) in the combo-box, the event handler executed and the message-box in the event handler showed the NEW value of (StrTransferByName) BUT the text box that is binded to to (StrTransferByName) did NOT update its value !! frowning

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-May-2005 19:19:28   

Hmm. Very strange.

The lame thing is: the event has to be called EXACTLY as the property, and has to have 'Changed' appended to it. I've checked the code above, it doesn't have a typo somewhere, but perhaps your real code does (unlikely, but still).

disappointed Databinding...

Frans Bouma | Lead developer LLBLGen Pro