StrataFrame Forum

Child fields are disabled

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

By Doron Farber - 6/4/2008

Hi All,

From some reason the Child fields are disabled on Add mode, but are fine in Edit mode. Somehow before it worked fine.  In the Child object the IncludeInFormAdd is True and in the form level the IncludeInFormAddType is DetermainedByBusinessObject. This is just an exercise for me to learn the SF, but the child and the parent should be saved at the same time. Using SF 1.6.5.1

Thanks,

Doron

By Trent L. Taylor - 6/4/2008

Have you debugged to actually see if the EditingState of the BO has changed to Adding?  It sounds like something within your configuration is preventing those BOs from being placed in an Add mode.  Since you are using the IncludeInForm stuff, the Edit and the Add states will be determined by the IncludeInForm properties.  You can adjust these settings until you get what you want...but in short, the EditingState of the BO did not change.
By Doron Farber - 6/4/2008

Hi Trent,

This is a maintenance form where the parent and the child fields are in the same form and using the tool strip for Adding or Editing each record. I followed all the steps shown in a video and in the help file and got the same problem. I could edit the child and the parent and under the Add mode the child was disabled. The EditingState was Adding initially and then later became Idle. Well I created a sample project with one form , from your sample database and had the same problem.

Please let me know how that can be fixed.

Thanks,

Doron
By Trent L. Taylor - 6/5/2008

It was a very simple problem...you have the ChildAutoFilterOption on the CustomersBO1 set to MatchCurrentRow.  So you will never be able to see a new child record.  This is a basic filtering problem, and you can find post after post in this regard.  I always caution people about using the ChildAutoFilter options and to be careful when using a filter or sort of any kind.  We use them all of the time, but you have to be aware of what will happen when you add a new record or change a value that is part of the filter or sort.

In this case, you could never add a new record because as soon as you create new Orders record the new row will be fitlered out (this is standard ADO.NET).  You need to turn off the filter, allow the foreign key to be set (in this example), then you could apply a filter that would include the new record. 

Bottom line, set the ChildAutoFilterOption to Off on the CustomersBO1 instance, run the app again, click add, and it will work.

By Doron Farber - 6/5/2008

Hi Trent,

That property really creates a lot of confusion after searching into the WinForms section. Me and Edhy were looking at this problem and made the same assumption of using the ChildAutoFilterOption property as MatchCurrentRow. In this thread you calrify it: http://forum.strataframe.net/Topic16681-6-1.aspx?Highlight=ChildAutoFilterOption

Regards,

Doron

By Trent L. Taylor - 6/5/2008

You can use it if you understand when to remove the filter and reapply it.  The post you pointed me to was really more complex than what you are trying to do in regards to the scenario that you gave me (I am sure that your code would be more complex).  However, the point of that post and what I have been telling you is that if you have a filter applied, automated or otherwise, and add a new record, that new record will be immediately filtered.
By Doron Farber - 6/5/2008

ok thanks Trent
By Doron Farber - 6/6/2008

Hi Trent,

What else can disabled the child fields in Add mode. In the parent BO the ChildAutoFilterOption is Off. In the project I created using your sample data it was fixed but not on my project. Hehe When I navigate the child is shown and I can edit the parent and the child as well.

Thanks,

Doron

By Trent L. Taylor - 6/6/2008

No records available within the BO (check the MyBo.Count) or the EditingState is Idle.  That's it.  I am 99.99% confident you still have a filter or no records in your BO.  I proved this on the sample you sent me, so I would assume that you are still fighting this.
By Doron Farber - 6/9/2008

Hi Trent,

Yes I fighting this and I  don't give up on it. This is strange since in the maintenance form the ChildAutoFilterOption is really OFF 100% this time. From the toolStrip New button I don't get it to work, but here is how in this form works for now  : Added a button with the following code:
 
  Me.MemberInfoBO1.Add()
  Me.AddressMemBO1.Add()
 
Then the child fields are enabled. If I use only this code:
Me.Add()
 
Then the child fields are disabled. 
 
I also noticed if I don't check the ChildBO.Count > 0 it will crash as well in case there are 0 records when I run it first. When I use the below code in the Navigated method then it is fixed.
 
BusinessLayerException
  The CurrentRow for table '[dbo].[AddressMem]' could not be evaluated because the CurrentRowIndex is out of range. 
Business object record count: 0.  CurrentRowIndex: -1.

While this field is casing it:
  Return CType(Me.CurrentRow.Item("MemberInfo_PK"), System.Int32)
 
Navigated method:
If Me.MemberInfoBO1.Count > 0 Then
      Me.AddressMemBO1.FillByParentPrimaryKey(Me.MemberInfoBO1.MemberInfo_PK)
End If
 
Then I tried to create the same form but based on the SF Standard form class and added the TootStrip and the GradientFormHeader and used again the same BOs and this form works just fine. When I click the New button, the child fields are enabled. Also when I run the form when there are 0 records It does not crash on me even though I don't check If Me.MemberInfoBO1.Count > 0 as shown above. I added that code anyway for other situations when I need to delete the parent and child.
 
Obviously something is happening with the maintenance form. Are there any known issues with this form?Smile Since still that form does not work for me using the ToolStrip and it worked on your test data. Hehe

Thanks,

Doron

By Doron Farber - 6/11/2008

Hi Trent,

Me and Edhy work together and we could not find out why the maintenance form does not work for us. The standard form works fine as explained in thread, I provided a lot of details there.
With the standard form I also could delete the child record with no problem and it does not happen in the maintenance form.

Please see again the below Smile and see why it does not work for us.

The frmMemberShipInfo1 is the maintenance while the frmMemberShipInfo2 is the standard one. The 2 tables that are involved are: MemberInfo and AddressMem. Very small database with several records only. The below is just a basic sample to show the problem.

http://www.dfarber.com/VRep/HumanFindAdmin.zip
http://www.dfarber.com/VRep/HumanFindAdmin_DATABASE.zip

Thanks,

Doron
By Trent L. Taylor - 6/11/2008

I tried to download your samples but got a firewall error on your end.  Just upload these as attachments if you can.

Just FYI, the funny thing you are fighting here, and if you look at the code, you will see that there is no such thing as a MaintenanceForm in SF.  The MaintenanceForm is just a template that comes with the framework the places a MaintenanceFormToolstrip on the form.  So if you are using a MaintenanceForm, you are actually using a StandardForm.  So this would alude to a configuration or code problem within your application.  Just thought this might point you in the right direction.

By Doron Farber - 6/12/2008

Hi Trent,

I fixed the Fire Walls issue on the server level so it is possible to download the zip files. I understand where you are coming from, but the properly which is responsible to disable the child field is OFF. Even though I made it to work in a different way, I would like to understand what else can cause this problem again.  I am still learning SF and .Net so I can easily over look something simple. Also please let me know when you Save at least one record if you see any delay in the Save mode - just curious.

Thanks,

Doron

By Trent L. Taylor - 6/19/2008

Doron,

I looked at your sample...and as I mentioned on a previous post, we do not have MaintenanceFormClass.  Your problem is actually very simple.  First, when you setup a test environment, make sure that you have the same code in both places...in this case you didn't (i.e. The Navigated event of the Members BO).

In order to make the form1 work, you will need to do the following:

  1. Set the IncludeInFormAdd property to True on the Address BO (it was not set)
  2. It would be a good idea to set the ParentBusinessObject on the address to the member (this is not the problem, but if you want SF to manage the foreign keys for you, you will want to do this)
  3. And here is your problem...REMOVE THE FILL CODE in the navigated event of the Members BO.  If you comment out this code, it works great.  The problem is that your code isn't taking into account a new record, etc.  If you want to have this type of Fill logic inside the navigated event, then you will want to be sure to test on new records, etc.  For example,

    If MembersBO.CurrentRow.RowState = Added Then
        '-- DON'T DO ANYTHING!
    End If
By Doron Farber - 6/20/2008

Hi Trent,
Thanks for your reply and see below.

Trent L. Taylor (06/19/2008)

And here is your problem...REMOVE THE FILL CODE in the navigated event of the Members BO.  If you comment out this code, it works great.  The problem is that your code isn't taking into account a new record, etc.  If you want to have this type of Fill logic inside the navigated event, then you will want to be sure to test on new records, etc.  For example,

If MembersBO.CurrentRow.RowState = Added Then
    '-- DON'T DO ANYTHING!
End If

If I remove the code found in the navigated method then when I click Next, Previous etc.. the child record will not be shown. Unless you have other suggestions to show the child record the below code works now:

Private Sub MemberInfoBO1_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles MemberInfoBO1.Navigated
If Me.MemberInfoBO1.CurrentRow.RowState <> Data.DataRowState.Added Then
    If Me.MemberInfoBO1.Count > 0 Then
        Me.AddressMemBO1.FillByParentPrimaryKey(Me.MemberInfoBO1.MemberInfo_PK)
    Else
        Me.AddressMemBO1.Refresh()
    End If
End If
End Sub


Did run the form one time? Just worndered if you saved one record.Hehe

Regards,

Doron
 

By Trent L. Taylor - 6/23/2008

Doron, you are missing the point.  You can put code in the Navigated event, but you need to check on the RowState to determine what action to take.  Your code ALWAYS attempted to FillByParentPrimaryKey (or something along those lines).  That code makes no sense for a new record.  So test on the row state to determine how to retrieve your data.
By Doron Farber - 6/23/2008

Ok Thanks