Parent/Child Maintenance Form Question


Author
Message
fparker
fparker
StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 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

Replies
fparker
fparker
StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 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 (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K 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.
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