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 (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
Edhy,

Thanks for the suggestions but neither did the trick. 

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.

  http://forum.strataframe.net/Uploads/Images/774cd579-0f5c-40bd-9e58-5a4d.jpg

Still, FWIW, I get the error as the BO is trying to set CLI_ID to NULL.  I can't tell if the "Null Replacement" process in SF is supposed to handle this or the inverse, returning a NULL.

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.

I am still struck by how odd this is:

a)  In the cboClient.SelectedChangeCommitted, I can do the CoverageBO.requery() alone and no problem.  So nothing in the CoverageBO is causing the problem.  It doesn't matter if it comes back filled or empty.  If all I was trying to do was a standard "synchronization" between related comboboxes, I'd be fine. 

b)  Similarly, in the cboClient.SelectedChangeCommitted, I can set the cboCoverage.SelectedValue alone and no problem.  So it doesn't seem to be a form or control refresh issue.

c)  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. 

d)  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.  It is not like I've left the combo blank; I'm getting a NULL error right as I make a selection.

Go figure. 

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.  Any suggestions on this, or other ideas on the problem, would be appreciated.

Larry
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Larry,

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.

There are several ways to deal with DBNulls:
  1. 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).
  2. 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>0 before you can try to use any of the BO.FieldProperty and avoid getting this error.


Edhy Rijo

Larry Tucker
Larry Tucker
StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
Hi all,

I'm stumped and have spent many hours puzzling over this.  I have two related comboxboxes, cboClient and cboCoverage on an EventBO maintenance form.   Each is bound to an FK on the EventBO record (CLI_ID and COV_ID). 

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.  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:



 Private Sub cboClient_SelectionChangeCommitted(sender As Object, e As System.EventArgs)_
     Handles cboClient.SelectionChangeCommitted
        Me.cboCoverage.Requery()
        Me.cboCoverage.SelectedValue = 50022155  ' simplified for demo
 End Sub



This works fine when editing an existing record.  It fails on a new record with the following error:

System.InvalidCastException was unhandled by user code
  Message=Conversion from type 'DBNull' to type 'Integer' is not valid.
  Source=Microsoft.VisualBasic
  StackTrace:
       at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value)
       at ThomBillerBOLibrary.EventBO.FieldDescriptor.SetValue(Object component, Object value) in E:\ThomBiller\ThomBillerBOLibrary\ThomBillerBOLibrary\EventBO.Designer.vb:line 3003
       at System.Windows.Forms.BindToObject.SetValue(Object value)
       at System.Windows.Forms.Binding.PullData(Boolean reformat, Boolean force)
  InnerException:


Specifically, this is happening as the EventBO is trying to set the CLI_ID value based on the cboClient selection:


        Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
            Select Case Me.Field
                Case EventBOFieldNames.EVE_ID
                    DirectCast(component, EventBO).EVE_ID = CType(value, System.Int32)
                Case EventBOFieldNames.OLDPK
                    DirectCast(component, EventBO).OLDPK = CType(value, System.String)
                Case EventBOFieldNames.CLI_ID
                    DirectCast(component, EventBO).CLI_ID = CType(value, System.Int32)


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.  If I am simply editing an existing EventBO record, I can do both.

TIA,

Larry
Tags
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