Error when I both requery a related combobox and set its selectedvalue in code (on new records...


Error when I both requery a related combobox and set its selectedvalue...
Author
Message
Larry Tucker
Larry Tucker
StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
Ivan and Edhy,

Thanks for the additional work on this.  I've been out of the office today and will get back to it tonight.  I know I tried both of these suggestions, but at this point, my head is spinning.  As I recall, the SelectedIndexChanged on combo1 was firing all the time.  When I limited the setting of the combo2 to only the times when a user actually selected something in combo1, I'm pretty sure I was getting the same error.  The benefit of SelectionChangeCommitted was that it fired only when a user made a change.  I'll take another shot a SelectedIndexChanged with these conditions and see what I can do.  I'll post the results.

Thanks very much,

Larry
Larry Tucker
Larry Tucker
StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
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
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Glad you got it working, Larry. Wink
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