StrataFrame Forum

Using custom properties to bind report fields

http://forum.strataframe.net/Topic15156.aspx

By Andria Jensen - 3/25/2008

I am using DevExpress XtraReports and have been able to make it work using a BusinessBindingSource as a DataSource, and then linking that BBS to a BO which has my report data in it.  I have done this many times already and have had no problems thus far.  I have been working on a problem for the past few days and haven't been able to figure out a solution.

I have several custom field properties on my BO which I have bound to fields in my report.  There are also several "regular" BO properties which link directly to fields in the db table.  The custom fields are all showing as blank, but the regular properties are showing as the correct values.  I don't think it is even getting to the code for the custom properties since I have set break points in them which are not getting hit.  I even tried hardcoding one of them to return a string value which also didnt show up. 

Its almost like it doesnt know how to find the custom properties.  I thought it was a problem with the binding, but if it can find the non-custom properties then it is binding correctly (I think).  Here is an example of one of the custom properties:

<Browsable(False), _
BusinessFieldDisplayInEditor(), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public ReadOnly Property TransferAmt() As Decimal
  Get
    Return FixAmt(Me.CurrentRow.Item("TransferAmt"))
  End Get
End Property

And I am also adding the custom property descriptors as I am supposed to, like the following:

Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor()

Return New MicroFour.StrataFrame.Business.FieldPropertyDescriptor() { _
 
New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("FacilityDescr", GetType(DailyTransactions)), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("DisburseAmt", GetType(DailyTransactions)), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("PaymentAmt", GetType(DailyTransactions)), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("StmtAmt", GetType(DailyTransactions)), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("FeePostAmt", GetType(DailyTransactions)), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("TransferAmt", GetType(DailyTransactions))}

End Function

Any advice, ideas, suggestions, etc?  Thanks!  I'm really stuck on this one.

By Trent L. Taylor - 3/25/2008

Is this business object inheriting from the another business object?  For example, do you have a CustomersBO and then this would be something like Customers_ReportBO that inherits the CustomersBO class?  There could be some "gotchas" there if this happens.  More than likely this is related to the .NET binding not reevaluating the type descriptors.  You can override a property on the BO called AreCustomDescriptorsEvaluated.  You can override this and, just for a test, return False.  This will be slow and if it resolves the issue I can tell you a permanent work around.

Protected Overrides ReadOnly Property AreCustomDescriptorsEvaluated() As Boolean
    Get
        Return False
    End Get
End Property

Note: DO NOT LEAVE THIS CODE AFTER TESTING!!! Smile

By Andria Jensen - 3/25/2008

You are right on the money.  Yes, I am inheriting from another business object, and yes when I overrode that property it fixed it.  So now....how about that permanent solution you were talking about??  Smile
By Trent L. Taylor - 3/25/2008

Just create a private and manage this manually for this BO.  If will look like this:


Private Shared _AreCustomDescriptorsEvaluated As Boolean = False

''' <summary>
''' Determine if the custom descriptors are going to be evaluated
''' </summary>
''' <remarks></remarks>
Protected Overrides ReadOnly Property AreCustomDescriptorsEvaluated() As Boolean
    Get
        '-- Establish Locals
        Dim r As Boolean = _AreCustomDescriptorsEvaluated

        '-- Do not eval the desciptors again
        _AreCustomDescriptorsEvaluated = True

        '-- Return results
        Return r
    End Get
End Property

Notice that the private is shared...this is an important step.  Add this and you will be good to go. Smile

By Peter Jones - 3/25/2008

Hi Andria,

Don't know if this will help or not but this is another approach to Type Descripters that Trent or Ben gave me advice on a little while ago:

Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor()

Dim DailyTran As System.Type = Me.GetType()

Return New MicroFour.StrataFrame.Business.FieldPropertyDescriptor() { _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("FacilityDescr", DailyTran), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("DisburseAmt", DailyTran), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("PaymentAmt", DailyTran), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("StmtAmt", DailyTran), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("FeePostAmt", DailyTran), _
  New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("TransferAmt", DailyTran)}

End Function

Cheers, Peter

By Andria Jensen - 3/25/2008

Ah, thanks.  That seems like an obvious time saver but I never noticed it before.  Good tip!

Trent, I'll try adding that in and see if it works for me.  Thanks!

By Trent L. Taylor - 3/25/2008

Peter is right in that this can be a time saver....however, in this particular scenario, I would caution you against using the me.GetType().  In this particular scenario since you are inheriting from another business object and extending that object, this can cause an issue when binding. 

Using the GetType(MyBo) is actually safer here since it is not pulling from the reference.  You can take the shortcut that Peter mentioned though, just use the GetType(MyBo) instead of the me.GetType() to get that reference:

Dim myType As System.Type = GetType(MyBo)
By Peter Jones - 3/26/2008

Hi Andrea,

Actually I wasn't suggesting this as an alternate way of doing the same thing. It actually fixed a problem I had in that it forced .Net to do the 'right thing'. Refer:

http://forum.strataframe.net/Topic13021-10-1.aspx

Cheers, Peter