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.
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..