So with Edhy's and Ivan's help, I've got it working. Again, the problem was that when I tried to set combo2 only when the user made a selection in combo1, it was failing on a New record. Using SelectedIndexChanged() helps, because it fires before the user has made a selection in combo1 and this somehow prevents the error. So all I had to do was allow this to happen in an innocuous way as the form finished loading, then trap a true user selection. To trap the user selection, I set a form property to hold the combo1's "before" value in its GotFocus(), then see if the "after" SelectedValue is different, indicating a user initiated change (not a simple navigation or form refresh()).
Here is the test code from the Strataframe Sample example. Again, the actual linking of Orders and Products makes no sense, I am just using them as "combo1" and "combo2".
Private Sub cboOrder_GotFocus(sender As Object, e As System.EventArgs) Handles cboOrder.GotFocus
Me._BeforeOrderValue = CInt(cboOrder.SelectedValue) ' combo1 before value
End Sub
Private Sub cboOrder_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboOrder.SelectedIndexChanged
'-- Skip this event when the form is loading.
If Me._FormIsLoading = True Then
Exit Sub
End If
If OrderItemsBO1.Count > 0 Then
Me.ProductsBO1.FillAll() 'combo2
Me.cboProduct.Requery() 'combo2
If Me.OrderItemsBO1.Count > 0 AndAlso Me.ProductsBO1.Count > 0 Then
If CInt(cboOrder.SelectedValue) = _BeforeOrderValue Then
OrderItemsBO1.orit_prod_pk = 0 ' innocuous value on new record with no user interaction
Else
OrderItemsBO1.orit_prod_pk = 2 ' desired value that would normally be based on something in combo1
End If
End If
End If
End Sub
This could probably be cleaned up. Again, in my real situation, I want the suggested value for combo2 to be based on some business logic (in my case, the recommended insurance coverage for the selected client in combo1 based on a number of factors). But here, at least, I am able to both requery() and set the value in combo2 based on user interaction in combo1. That was the general problem and hopefully this is helpful to others. It certainly was for me. Thanks again Edhy and Ivan.
Larry