Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Glad you got it working, Larry.
|
|
|
Larry Tucker
|
|
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
|
|
|
Larry Tucker
|
|
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
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Hi Larry, Ivan, Well, basically the problem was that the Primary Key value of the main BO was being DBNull and this would crash in the BO PropertyDescriptor, all I did was Setup a "Return Alternate on Null" = 0 for the Pirmay Key field in the case of this sample that would be the OrderItemsBO.orit_pk and that would ignore the error and continue assigning the custom value in the cboOrder.SelectedIndexChanged event. I know on PK fields you hardly need to handle Null, specially when the field is an autoinc integer, but this seems to work just fine for Larry's particular requirement.
Edhy Rijo
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
I used the SelectedIndexChanged on your sample and didn't get the error. But maybe your situation has a different scenario.
|
|
|
Larry Tucker
|
|
Group: StrataFrame Users
Posts: 69,
Visits: 308
|
Hi Ivan,
Thanks for the suggestion, but yes, we did try the SelectedIndexChanged event as well.
It seems that the effort to set the value in cbo2 while the selection process is completing in cbo1 is somehow fouling up the process in cbo1. In the error, it is as if the cbo1 has a null value, even though it is in the process of being selected. And even when nothing is selected for cbo1, the save will still work without an error with a 0 default value instead of a NULL.
Larry
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hi Larry.
You are using the SelectionChangeCommitted event, have you tried putting your code on the SelectedIndexChanged instead?
|
|
|
Larry Tucker
|
|
Group: StrataFrame Users
Posts: 69,
Visits: 308
|
Just an update for others out there. Edhy and I spent two hours on this today by remote connection with no luck. I really appreciated the effort. I'm now looking into a kludge of sorts: setting timer on cbo1 so that it can finish whatever it needs to do before cbo2 setting the value in cbo2.
Larry
|
|
|
Larry Tucker
|
|
Group: StrataFrame Users
Posts: 69,
Visits: 308
|
Edhy, Thank you for taking the time to put together a demo. I was able to modify it (and misuse the poor Stataframe Sample database) to demonstrate my problem. Again, the issue is not how to synchronize two combos. I am able to do that as your demo demonstrated. The problem is adding a step to the synchronization which involves setting a suggested value in combo 2. The reason this is important to me is that in my medical billing application, a given client can have multiple insurance coverage records with different priorities, different dates, different services covered. When I am entering charges, and I select a client, I want the coverage (cbo2) to refresh with only that client's coverages and "stop" on the one that fits the current date, service, etc. In other words, on new records, when I select a client on cbo1 I want a recommended selection to appear on cbo2. (On existing records, I will actually compare the existing cbo2 value to the recommended on and give them a warning if they have the wrong one.) I got this working when editing an existing charge record. It fails when working on a new charge. It turns out that the problem is being cause by this second action: setting cbo2.SelectedValue = <MyRecommendCoverage>. Since this is being done from within the cbo1 selection process (within cbo1.SelectedChangeCommitted(() event handler) I think it is somehow short-circuiting the normal selection process on that combo. The error is being thrown by the form's "ISA" as it tries to save the cbo1 selection. Anyway, this revised demo will show the same error. I had to misuse the Strataframe Sample database because I needed a table with two FKs on it. So I picked OrderItems because it has two FKs to Orders and Products. You have to suspend some critical thinking when you use the demo, because in reality it makes no sense to have a OrderItemsMaintenanceForm like I built. But on it, I use cboOrders and cboProducts as stand-ins for the truly related Client and Coverage tables in my real database. Just think of them as cbo1 and cbo2, and pretend that cbo2 is a child of cbo1, and that when you pick something in cbo1, it not only refreshes cbo2 but also sets a suggested value. This will throw the same error I have been getting when you try it on a New record. Whew... Thanks very much. Larry
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Hi Larry, Sometimes, this kind of situation are better explained with a small and quick sample application, so here it is. I created the small VB application which will show 2 comboboxes using data from the StrataFrameSample database. It is pretty basic and straight forward: When you select a customer from combobox 1, the CustomerNotes combo will be populated with all the notes for the selected customer. Pay attention to the Population used in the comboxes as well as their events. If the comboboxes are binded to the BO, then there is no need to update the 2nd combo SelectedValue since the binding will take care of that for you. If I misunderstood you situation, then use this sample to duplicate your issue and post it again so we can all learn from it.
Edhy Rijo
|
|
|