﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Wed, 06 May 2026 02:47:16 GMT</lastBuildDate><ttl>20</ttl><item><title>Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31081.aspx</link><description>Hi all,&lt;br/&gt;&lt;br/&gt;I'm stumped and have spent many hours puzzling over this.&amp;nbsp; I have two related comboxboxes, cboClient and cboCoverage on an EventBO maintenance form.&amp;nbsp;&amp;nbsp; Each is bound to an FK on the EventBO record (CLI_ID and COV_ID).&amp;nbsp; &lt;br/&gt;&lt;br/&gt;When the user selects a new Client, I want the cboCoverage to requery showing only the coverages for this particular client and I want to set its selected value in code to a particular one of the coverage choices.&amp;nbsp; The logic for this doesn't matter here (I am actually setting the recommended coverage for that client based on several other variables...); here is an ultra simplified version setting a fixed value in code just for demo:&lt;br/&gt;&lt;br/&gt;&lt;span&gt;[codesnippet]&lt;br/&gt;&lt;br/&gt;&amp;nbsp;Private Sub cboClient_SelectionChangeCommitted(sender As Object, e As System.EventArgs)_&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Handles cboClient.SelectionChangeCommitted&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.cboCoverage.Requery()&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.cboCoverage.SelectedValue = 50022155&amp;nbsp; ' simplified for demo&lt;br/&gt;&amp;nbsp;End Sub&lt;br/&gt;&lt;br/&gt;[/codesnippet]&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;This works fine when editing an existing record.&amp;nbsp; It fails on a new record with the following error:&lt;br/&gt;&lt;span&gt;[codesnippet]&lt;/span&gt;&lt;br/&gt;System.InvalidCastException was unhandled by user code&lt;br/&gt;&amp;nbsp; Message=Conversion from type 'DBNull' to type 'Integer' is not valid.&lt;br/&gt;&amp;nbsp; Source=Microsoft.VisualBasic&lt;br/&gt;&amp;nbsp; StackTrace:&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value)&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at ThomBillerBOLibrary.EventBO.FieldDescriptor.SetValue(Object component, Object value) in E:\ThomBiller\ThomBillerBOLibrary\ThomBillerBOLibrary\EventBO.Designer.vb:line 3003&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.BindToObject.SetValue(Object value)&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Binding.PullData(Boolean reformat, Boolean force)&lt;br/&gt;&amp;nbsp; InnerException: &lt;br/&gt;&lt;span&gt;[/codesnippet]&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;Specifically, this is happening as the EventBO is trying to set the CLI_ID value based on the cboClient selection:&lt;br/&gt;&lt;br/&gt;&lt;span&gt;[codesnippet]&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select Case Me.Field&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Case EventBOFieldNames.EVE_ID&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DirectCast(component, EventBO).EVE_ID = CType(value, System.Int32)&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Case EventBOFieldNames.OLDPK&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DirectCast(component, EventBO).OLDPK = CType(value, System.String)&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background-color: rgb(255, 255, 0);"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Case EventBOFieldNames.CLI_ID&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);"&gt;&lt;span style="background-color: rgb(255, 255, 0);"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DirectCast(component, EventBO).CLI_ID = CType(value, System.Int32)&lt;/span&gt;&lt;br/&gt;[/codesnippet]&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;What is so odd is that on a new EventBO record, I can either requery() the related cbo or set its selectedvalue without error, but not both.&amp;nbsp; If I am simply editing an existing EventBO record, I can do both.&lt;br/&gt;&lt;br/&gt;TIA,&lt;br/&gt;&lt;br/&gt;Larry</description><pubDate>Mon, 09 Apr 2012 13:59:02 GMT</pubDate><dc:creator>Larry Tucker</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31107.aspx</link><description>Glad you got it working, Larry. &lt;span&gt;;)&lt;/span&gt;</description><pubDate>Mon, 09 Apr 2012 13:59:02 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31101.aspx</link><description>So with Edhy's and Ivan's help, I've got it working.&amp;nbsp; 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.&amp;nbsp; Using SelectedIndexChanged() helps, because it fires before the user has made a selection in combo1 and this somehow prevents the error.&amp;nbsp; 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.&amp;nbsp; 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()).&lt;br/&gt;&lt;br/&gt;Here is the test code from the Strataframe Sample example.&amp;nbsp; Again, the actual linking of Orders and Products makes no sense, I am just using them as "combo1" and "combo2".&lt;br/&gt;&lt;br/&gt;&lt;span&gt;[codesnippet]&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub cboOrder_GotFocus(sender As Object, e As System.EventArgs) Handles cboOrder.GotFocus&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me._BeforeOrderValue = CInt(cboOrder.SelectedValue) ' combo1 before value&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;br/&gt;&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub cboOrder_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboOrder.SelectedIndexChanged&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Skip this event when the form is loading.&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Me._FormIsLoading = True Then&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If OrderItemsBO1.Count &amp;gt; 0 Then&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.ProductsBO1.FillAll()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'combo2&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.cboProduct.Requery()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'combo2&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Me.OrderItemsBO1.Count &amp;gt; 0 AndAlso Me.ProductsBO1.Count &amp;gt; 0 Then&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If CInt(cboOrder.SelectedValue) = _BeforeOrderValue Then&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OrderItemsBO1.orit_prod_pk = 0 ' innocuous value on new record with no user interaction&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OrderItemsBO1.orit_prod_pk = 2 ' desired value that would normally be based on something in combo1&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;br/&gt;&lt;br/&gt;[/codesnippet]&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;This could probably be cleaned up.&amp;nbsp; 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).&amp;nbsp; But here, at least, I am able to both requery() and set the value in combo2 based on user interaction in combo1.&amp;nbsp; That was the general problem and hopefully this is helpful to others.&amp;nbsp; It certainly was for me.&amp;nbsp; Thanks again Edhy and Ivan.&lt;br/&gt;&lt;br/&gt;Larry</description><pubDate>Fri, 06 Apr 2012 09:55:15 GMT</pubDate><dc:creator>Larry Tucker</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31094.aspx</link><description>Ivan and Edhy,&lt;br/&gt;&lt;br/&gt;Thanks for the additional work on this.&amp;nbsp; I've been out of the office today and will get back to it tonight.&amp;nbsp; I know I tried both of these suggestions, but at this point, my head is spinning.&amp;nbsp; As I recall, the SelectedIndexChanged on combo1 was firing all the time.&amp;nbsp; 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.&amp;nbsp; The benefit of SelectionChangeCommitted was that it fired only when a user made a change.&amp;nbsp; I'll take another shot a SelectedIndexChanged with these conditions and see what I can do.&amp;nbsp; I'll post the results.&lt;br/&gt;&lt;br/&gt;Thanks very much,&lt;br/&gt;&lt;br/&gt;Larry</description><pubDate>Tue, 03 Apr 2012 14:09:38 GMT</pubDate><dc:creator>Larry Tucker</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31090.aspx</link><description>Hi Larry, Ivan,&lt;br/&gt;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.&lt;br/&gt;&lt;br/&gt;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.</description><pubDate>Mon, 02 Apr 2012 22:55:48 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31089.aspx</link><description>I used the SelectedIndexChanged on your sample and didn't get the error. But maybe your situation has a different scenario.</description><pubDate>Mon, 02 Apr 2012 17:07:21 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31088.aspx</link><description>Hi Ivan,&lt;br/&gt;&lt;br/&gt;Thanks for the suggestion, but yes, we did try the SelectedIndexChanged event as well.&lt;br/&gt;&lt;br/&gt;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.&amp;nbsp; In the error, it is as if the cbo1 has a null value, even though it is in the process of being selected.&amp;nbsp; 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.&lt;br/&gt;&lt;br/&gt;Larry</description><pubDate>Mon, 02 Apr 2012 16:37:29 GMT</pubDate><dc:creator>Larry Tucker</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31087.aspx</link><description>Hi Larry.&lt;br/&gt;&lt;br/&gt;You are using the SelectionChangeCommitted event, have you tried putting your code on the SelectedIndexChanged instead?</description><pubDate>Mon, 02 Apr 2012 15:09:11 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31086.aspx</link><description>Just an update for others out there.&amp;nbsp; Edhy and I spent two hours on this today by remote connection with no luck.&amp;nbsp; I really appreciated the effort.&amp;nbsp; I'm now looking into a kludge of sorts:&amp;nbsp; setting timer on cbo1 so that it can finish whatever it needs to do before cbo2 setting the value in cbo2.&lt;br/&gt;&lt;br/&gt;Larry</description><pubDate>Mon, 02 Apr 2012 14:27:51 GMT</pubDate><dc:creator>Larry Tucker</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31085.aspx</link><description>Edhy,&lt;br/&gt;&lt;br/&gt;Thank you for taking the time to put together a demo.&amp;nbsp; I was able to modify it (and misuse the poor Stataframe Sample database) to demonstrate my problem.&lt;br/&gt;&lt;br/&gt;Again, the issue is not how to synchronize two combos.&amp;nbsp; I am able to do that as your demo demonstrated.&lt;br/&gt;&lt;br/&gt;The problem is adding a step to the synchronization which involves setting a suggested value in combo 2.&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; In other words, on new records, when I select a client on cbo1 I want a recommended selection to appear on cbo2.&amp;nbsp; (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.)&lt;br/&gt;&lt;br/&gt;I got this working when editing an existing charge record.&amp;nbsp; It fails when working on a new charge.&lt;br/&gt;&lt;br/&gt;It turns out that the problem is being cause by this second action:&amp;nbsp; setting cbo2.SelectedValue = &amp;lt;MyRecommendCoverage&amp;gt;.&amp;nbsp;&amp;nbsp; 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.&amp;nbsp; The error is being thrown by the form's "ISA" as it tries to save the cbo1 selection.&lt;br/&gt;&lt;br/&gt;Anyway, this revised demo will show the same error.&amp;nbsp; I had to misuse the Strataframe Sample database because I needed a table with two FKs on it.&amp;nbsp; So I picked OrderItems because it has two FKs to Orders and Products.&amp;nbsp; &lt;br/&gt;&lt;br/&gt;&lt;img src="http://forum.strataframe.net/Uploads/Images/5ba4eac9-9211-485a-bcf2-454b.jpg" alt="http://forum.strataframe.net/Uploads/Images/5ba4eac9-9211-485a-bcf2-454b.jpg" /&gt;&lt;br/&gt;&lt;br/&gt;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.&amp;nbsp; But on it, I use cboOrders and cboProducts as stand-ins for the truly related Client and Coverage tables in my real database.&amp;nbsp; 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.&amp;nbsp; This will throw the same error I have been getting when you try it on a New record.&amp;nbsp; Whew...&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;Thanks very much.&lt;br/&gt;&lt;br/&gt;Larry</description><pubDate>Mon, 02 Apr 2012 10:09:46 GMT</pubDate><dc:creator>Larry Tucker</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31084.aspx</link><description>Hi Larry,&lt;br/&gt;Sometimes, this kind of situation are better explained with a small and quick sample application, so here it is.&amp;nbsp; I created the small VB application which will show 2 comboboxes using data from the StrataFrameSample database.&lt;br/&gt;It is pretty basic and straight forward:&amp;nbsp; When you select a customer from combobox 1, the CustomerNotes combo will be populated with all the notes for the selected customer.&lt;br/&gt;Pay attention to the Population used in the comboxes as well as their events.&amp;nbsp; 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.&lt;br/&gt;If I misunderstood you situation, then use this sample to duplicate your issue and post it again so we can all learn from it.</description><pubDate>Sun, 01 Apr 2012 17:06:54 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31083.aspx</link><description>Edhy,&lt;br/&gt;&lt;br/&gt;Thanks for the suggestions but neither did the trick.&amp;nbsp; &lt;br/&gt;&lt;br/&gt;For 1, I set the CLI_ID Null Replacement Value as shown below, rebuilt both the EventBO partial and solution, and got the same error.&lt;br/&gt;&lt;br/&gt;&amp;nbsp; &lt;img src="http://forum.strataframe.net/Uploads/Images/774cd579-0f5c-40bd-9e58-5a4d.jpg" alt="http://forum.strataframe.net/Uploads/Images/774cd579-0f5c-40bd-9e58-5a4d.jpg" /&gt;&lt;br/&gt;&lt;br/&gt;Still, FWIW, I get the error as the BO is trying to &lt;span style="font-weight: bold;"&gt;set &lt;/span&gt;CLI_ID to NULL.&amp;nbsp; I can't tell if the "Null Replacement" process in SF is supposed to handle this or the inverse, &lt;span style="font-weight: bold;"&gt;returning &lt;/span&gt;a NULL.&lt;br/&gt;&lt;br/&gt;As for 2, changing the lookup BO (CoverageBO) to something manipulated on the form and then copied into the dropdown did not change the result either.&lt;br/&gt;&lt;br/&gt;I am still struck by how odd this is:&lt;br/&gt;&lt;br/&gt;a)&amp;nbsp; In the cboClient.SelectedChangeCommitted, I can do the CoverageBO.requery() alone and no problem.&amp;nbsp; So nothing in the CoverageBO is causing the problem.&amp;nbsp; It doesn't matter if it comes back filled or empty.&amp;nbsp; If all I was trying to do was a standard "synchronization" between related comboboxes, I'd be fine.&amp;nbsp; &lt;br/&gt;&lt;br/&gt;b)&amp;nbsp; Similarly, in the  cboClient.SelectedChangeCommitted, I can set the cboCoverage.SelectedValue alone and no problem.&amp;nbsp; So it doesn't seem to be a form or control refresh issue. &lt;br/&gt;&lt;br/&gt;c)&amp;nbsp; But if I try to do them both, synchronize and set the related combo, it fails... but only if I am on a new record.&amp;nbsp; &lt;br/&gt;&lt;br/&gt;d)&amp;nbsp; And finally, the error is saying the field is NULL when it is in fact bound to the combobox I just made a selection on.&amp;nbsp; It is not like I've left the combo blank; I'm getting a NULL error right as I make a selection.&lt;br/&gt;&lt;br/&gt;Go figure.&amp;nbsp; &lt;br/&gt;&lt;br/&gt;Unfortunately, I don't yet have the VS debugging skills to walk back from the error and see what is going on in the SF code.&amp;nbsp; Any suggestions on this, or other ideas on the problem, would be appreciated.&lt;br/&gt;&lt;br/&gt;Larry</description><pubDate>Sun, 01 Apr 2012 10:21:28 GMT</pubDate><dc:creator>Larry Tucker</dc:creator></item><item><title>RE: Error when I both requery a related combobox and set its selectedvalue in code (on new records only!)</title><link>http://forum.strataframe.net/FindPost31082.aspx</link><description>Hi Larry,&lt;br/&gt;&lt;br/&gt;What I believe is happening is that when you requery your combobox, it is not bringing any records then you are getting a DBNull value.&lt;br/&gt;&lt;br/&gt;There are several ways to deal with DBNulls:&lt;br/&gt;&lt;ol&gt;&lt;li&gt;In the BOM, set the appropriate Null value replacement so it will be used when a DBNull is found, in your case if your FK values are Integers use zero (0).&lt;/li&gt;&lt;li&gt;For my listview and comboboxes I always use a BO instance dropped in the form, then I fill the BO and use the list/combo population method to show the data, in that case you can always check if the BO has any records BO.Count&amp;gt;0 before you can try to use any of the BO.FieldProperty and avoid getting this error.&lt;br/&gt;&lt;/li&gt;&lt;/ol&gt;</description><pubDate>Sat, 31 Mar 2012 16:55:47 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item></channel></rss>