StrataFrame Forum

One Custom Field Shows and The Other Does Not

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

By Terry Bottorff - 12/30/2011

I have a Form where I am trying to use 2 Custom Fields. One works as it should the other does not?

I have attached a picture showing that the Custom Field shows up in the BO Visualizer and a picture showing that it does Not show up in a MessageBox nor a Bound Text box???????

Here is my Custom Field Code:

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

Return New MicroFour.StrataFrame.Business.FieldPropertyDescriptor() { _

New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("Cowboy_Name", GetType(MyBaseRoughStockBO)), _

New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("Cowboy_InvertedName", GetType(MyBaseRoughStockBO)), _

New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("PRCANUM", GetType(MyBaseRoughStockBO))}

End Function

<

Browsable(False), _



BusinessFieldDisplayInEditorAttribute(), _
Description("PRCA Number"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _

Public ReadOnly Property PRCANUM() As String

Get

' Return MyBase.RequiredFields

If Me.CurrentDataTable.Columns.Contains("Membershipcd") Then

If Not TypeOf (Me.CurrentRow.Item("membershipcd")) Is DBNull Then

Return CStr(Me.CurrentRow.Item("membershipcd")) + Me.CurrentRow.Item("membershipnumber").ToString

Else

Return ""

End If

Else

Return ""

End If

End Get

End Property

 

I'm Sorry I can not get the last part to format correctly? This is the Custom Field that Shows in the BO but not in the MessageBox nor the Bound Text Box?

TIA.

 

 

   
By Edhy Rijo - 12/30/2011

Hi Terry,

Couple of things...
  1. Why are you checking if "Membershipcd" exist? could it be possible that this field would not exist in this BO? or is this part of another table and you are using a JOIN SELECT to get this field?, if this is the case, then the field will only have a value when getting the data, so at the time you are using this property, it may not have any value.
  2. When using custom field properties (CFP) that will use values of the BO fields, I prefer to use the Me.FieldName instead of the Me.CurrentRow.Item("ItemName").  Also if you set your BO properties in the BOM to deal with Null values, then you don't need to check for DBNull, only check the property value directly.
By Terry Bottorff - 12/30/2011

I am using a Join Select to get it out of another table. It is working with the other name field and the Name field and prcanum field are both coming out of the same joined table?????? 

I am checking to see if it exist since that was part of a sample I saw and used one time. It will be there and I believe I already am dealing with it in the BO. Yes I do handel it in the BO so I really don't need that piece. Just left over from a copy and paste when I started using CFP.

Any other Thoughts?

Have a Great and Prosperous New Years.
By Edhy Rijo - 12/30/2011

Hi Terry,

Ok, if using a JOIN to get the field, then your code is OK.  Basically what is happening is that when you are accessing the BO.PRCANUM, if those fields included in the JOIN are empty, then you will not get anything, this could happen when adding a new record and trying to show the BO.PRCANUM will be empty.

If you debug the code before showing the message box image, you will see the field is empty.  Put a breakpoint in your property Get line and see what happen when showing the value in the message box.

On a side note, I try to distinguish my Custom Field Properties form regular BO properties by prefix them with "cfp_", also in my JOIN SELECT I name those fields with the prefix ex: SELECT membershipcd AS cfp_membershipcd or do the expression at the field level instead of the BO like SELECT (membershipcd + membershipnumber) AS cfp_PRCANUM, then in the BO CFP I use the required column as expected.  I use a lot of CFPs and in some cases like when adding a new record, I need to show the value, so in the CFP GET I check for empty value and even do a search to show the correct value, here is a sample:


    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("Card Name with the Card Code."), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
     Public Overridable ReadOnly Property [cfp_CardName]() As String
         ' Check to see if datatable contains the custom field in
         ' case object was filled by a method that doesn't contain the field.
         Get
             Dim columnName As String = "cfp_CardName"
             If Me.CurrentDataTable.Columns.Contains(columnName) Then
                 If Not TypeOf (Me.CurrentRow.Item(columnName)) Is DBNull Then
                     '-- In some cases the Me.CurrentRow.Item(columnName) could be empty so
                     '   lets look at the value if there is a FK_Items value
                     Dim cfpCardName As String = CStr(Me.CurrentRow.Item(columnName))
                     If String.IsNullOrEmpty(cfpCardName) And Me.Count > 0 Then
                         Using bo As New bizItems
                             bo.FillByPrimaryKey(Me.FK_Items)
                             If bo.Count > 0 Then
                                 cfpCardName = bo.ItemName
                             End If
                         End Using
                     End If
                     Return cfpCardName
                 Else
                     Return String.Empty
                 End If
             Else
                 Return String.Empty
             End If
         End Get
     End Property


Hope that will give you an idea to help you find the issue.

P.S.
Happy new year to you too!!!!
By Terry Bottorff - 12/31/2011

Edhy I have not put any of your code into use yet but I will but I thought I would show you some other pictures so you can see what I think is working yet not working?

The first picture is the BO visualizer that shows the CF and at least Visually they are Full. Then I show you the Synch List with text boxes and in the Synch List one of the CF show up and one of the CF shows in a bound text box but not the PRCANum in the other bound textbox. Also, then the messagebox shows blank for the me.bbpointsbo1.prcanum ......

Then I added the CF to the synch list and they all show as blanks but again Visually in the BO Visualizer they are all there?
By Terry Bottorff - 12/31/2011

Op's I forgot the synch list with the CF added to it.

Could it be because it is a Calculated CF?
By Edhy Rijo - 12/31/2011

Hi Terry,

So the problem is that it is not showing in a listview?

I believe my previous explanation has a lot to do because it is a calculated field as such the CFP will only contain data when the source SELECT returns the data for it.  With listview it could be tricky in a sense of how you are loading its data ex ParentFormLoading VS manually loading.  I love SF ListViews, but I learned in a hard way that it is a good idea to have control on when to load the data (lv.Refresh()), so in the listview Populate data settings I always use a copy data from bo and manually drop a BO instance in the form, assign it to the list view and fill this BO manually then refresh the listview.

Now if after reviewing my suggestions still you don't get it to work, please create a small VB sample project using one of the SF Sample database tables that would duplicate the issue and upload it here, I will gladly take a look and make it work or if you prefer, I can do one remote support session to take a look at the issue on hand with your project, feel free to email for connection details.
By Terry Bottorff - 1/2/2012

Edhy I put a Break on the Get and I must have changed something else because it is working. I have NO IDEA why. I did delete some of my code and put some of your code into play and so I am sure I had some weird character in my code that your code fixed.

Thanks so much.

I don't believe how much time I spent chasing a mystery....!
By Edhy Rijo - 1/2/2012

Hi Terry,

Glad it is working out.
By Terry Bottorff - 1/2/2012

Well after all of this. I was getting an error every not and again so it was time to delete the whole form and start again. Even started with a little older version of the project. Everything seems to work now so I am really not sure about any of the problems I was having.

Just a bug in the night I think.
By Fabian R Silva, - - 5/14/2012

Greetings,sorry for revive this post.

I only like to say thank you Edhy and Terry for this post, I was out of ideas on how to populate a BO from a join and use a custom field to use some fk fields on a form and here you propose a good solution using the rows of the datatable. this is x1000 better than using a scalar value on each get to give to the BO value by value.

Thanks again!.
By Edhy Rijo - 5/14/2012

You are welcome Fabian.
By Terry Bottorff - 5/14/2012

Your welcome but Edhy is the real help. He's here for everyone.
By Edhy Rijo - 5/14/2012

Terry Bottorff (5/14/2012)
Your welcome but Edhy is the real help. He's here for everyone.

Hi Terry,

Thanks so much for the kind words, but I am simply doing what others have done for me before, in this and other communities like VFP and by the way, it is a good way to keep learning Tongue
By Terry Bottorff - 5/14/2012

I agree I learn more here then anything I can do.