Parent/Child Maintenance Form Question


Author
Message
fparker
fparker
StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)
Group: Forum Members
Posts: 31, Visits: 199
Hello All,

I have a maintenance form with two business objects on it.  They are arranged in a parent/child relationship.  I also have some text boxes bound to each object on the form.  When the user hits the new button, I'd like a record to be created in both objects.  The primary key is not auto incremented on either object.  If I set the Form's IncludeInFormAddType property to AllBusinessObjects, I get a BusinessLayerException ("An error occurred while retrieving the primary key from the parent business object").  If I instead set the IncludeInFormAddType property back to PrimaryBusinessObject and put a call to the child object's Add() method in the handler for the parent object's AfterAddNew event, no exception will be raised and the child objects editing state will be Adding but the controls associated with the child object do not become enabled.  Is there a way to get this to work?  Thanks for your help.

Fran Parker

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
It's very strange that the controls bound to the child business object are still disabled even when the business object is adding... Most likely, the problem is that the child business object was dropped on the form in the designer before the parent business object was dropped on the form, so it exists within the BusinessObjects collection before the parent does.  The form will then try to add a record to the child before it has added a record to he parent.  You best bet is still to leave the call to Child.Add() within the AfterAddNew() of the parent record.  The only difference is that you might call Child.Refresh() after you call Child.Add() to make sure that the controls get enabled.
fparker
fparker
StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)
Group: Forum Members
Posts: 31, Visits: 199
Ben,

Unfortunately, this problem isn't so easily fixed.  I think its a bug in the way parent/child relationships are handled.  Here's what I found: after the call to the child object's Add() method, its count property is 0 but the number of rows in its datatable is 1.  Because the child's CurrentView contains no rows, its Refresh() method had no affect.  As I mentioned in my first message, the primary keys of these objects are not auto-incremented.  Because the key fields are bound to textboxes, I had to set those properties to return an empty string when null (in order to keep an exception about assigning DBNull to the text property of the textbox from being thrown when a new record is added). So, what's happening is that in the parent object's AfterAddNew event, its primary key property returns an empty string but the corresponding field in its CurrentDataTable is DBNull.  When the child object's Add() method is called inside this event, a new row is added to the child's CurrentDataTable.  The field in this new row that corresponds to the parent object's primary key will be DBNull but the CurrentView's rowfilter will be ParentPrimaryKeyField = ''.  Let me know what you think.  Thanks for your help.

Fran Parker

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yes, if you have the ChildAutoFilterOption to anything other than the default, you are certainly going to get some quirkyness when you are manually assigning primary keys.  You will most likely have to remove the .Filter from the CurrentView on the child business object, add the row, and set the current view back.  If the CurrentDataTable has rows, but the CurrentView has 0 rows, then there must be a filter set on the business object.
Peter Jones
Peter Jones
Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Ben,

I have an interest in this as I knocked together a parent/child form yesterday to check out how things worked - easy to do and worked 'as expected'. Your comments about having ChildAutoFilterOption set to something other than the default is a bit confusing. The default for ChildAutoFilterOption seems to be 'Off' - are you saying this is the best thing to do and handle the child form population manually?

I have ChildAutoFilterOption set to MatchCurrentRow and it works fine. The PKs (a GUID) for both forms are manually created and I can add/delete new child records without any problems (or so it seems).

Cheers, Peter

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Yes, this will work fine and we would not have the feature if it did not work.  Ben was warning about using this setting when adding new records.  Since the filter is automatically applied to the foreign keys then when a new record is created the child record will more than likely not be visible within the collection.  So it is best to set this to Off anytime a new parent or child record is being created until the foreign key fields have been set then you can turn it back on.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search