You're close! Your BOs and relationships are set up correctly, you just have a couple small issues on populating the BOs and programatically creating that record
.
The reason your orderitems aren't getting saved is that you are doing a FillByParentPrimaryKey in the Navigated event of the orders business object. This event gets fired when you return from the Orders child form. As a result, any changes to your OrdersItems business object were getting overwritten once you returned to the parent form.
Rather than loading the orders and order items in seperate queries (which requires a server trip every time you click an item in the orders list), I'd recommend you do a FillMultipleDataTables whenever you pick the customer you want to work with, and then just filter BizOrderItems1 down to the pertinate records on the navigate of BizOrders1. In effect, BizOrderItems1 will contain all orderitems records for all orders associated with the selected customer but, due to the filter, will only show the orderitems for the currently selected order. This would be a much more efficient approach in terms of server trips, and has the added benifit of not clearing out your grandchild BO every time the child BO navigates .
You would call FillMultipleDataTables on the BizCustomers1 navigated event of the Customers form to make it work as it stands.
Private Sub BizCustomers1_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles BizCustomers1.Navigated
'-- Get all Orders for the current Customer.
If BizCustomers1.Count > 0 AndAlso BizCustomers1.Then
' Call FillMultipleDataTables here
End If
lvOrders.Requery()
End Sub
Note: The above is how to make it work in your existing form, but it isn't how we would typically do it. From a form-design standpoint, we don't typically load a bunch of records and then use forward and back buttons to navigate through them. Instead, we typically call a browse, pick the specific customer record to work with, and then call FillMultipleDataTables upon the return of the browse form.
That will keep your order items from being overwritten. To get them to actually save, you'll need to address a couple of things when you programatically create the record. You would have seen and corrected these yourself, I'm sure, but since I was already in there, I thought I would point them out .
On the orders form, change this:
Private Sub cmdAddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddToolStripMenuItem.Click
Me.BizOrderItems1.NewRow()
Me.BizOrderItems1.orit_or_pk = Me.BizOrders1.or_pk
Me.BizOrderItems1.orit_prod_pk = 235
Me.lvOrderItems.Requery()
End Sub
To this:
Private Sub cmdAddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddToolStripMenuItem.Click
Me.BizOrderItems1.NewRow()
Me.BizOrderItems1.orit_or_pk = Me.BizOrders1.or_pk
Me.BizOrderItems1.orit_prod_pk = 1
Me.lvOrderItems.Requery()
End Sub
Basically, you don't need to set the orderitems primary key (it does it for you), but you do need to specify a valid product id (in production, you'll likely need some kind of user input rather than hardcoding a specific product.)
Hope it helps!