Windows Develop Bookmark and Share   
 index > Windows Forms General > ComboBox1.SelectedValue = 64 causes crash
 

ComboBox1.SelectedValue = 64 causes crash

If I try to programatically assign a value of 64 to a combobox through the SelectedValue property I get an error (shown below).  I can set it to any value I want except 64. 

Do you have any insight on this?

Thanks,

- Dan

--error message--
"System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: '-2147483648' is not a valid value for 'index'.
at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)
at System.Windows.Forms.ListControl.set_SelectedValue(Object value)
at UnhandledEx.Form2.Button1_Click(Object sender, EventArgs e) in C:\Projects\Test\Form2.vb:line 257"
--error message--


... code in the page load
   ComboBox1.DataSource = dtUsers
   ComboBox1.DisplayMember = "Name"
   ComboBox1.ValueMember = "EmployeeID"
... code in the page load

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim x As Int64
   Try
      If IsNumeric(TextBox1.Text) Then
         x = CDbl(TextBox1.Text)
      End If
      If IsDBNull(x) = True Then
         ComboBox1.FindString("")
      Else
         ComboBox1.SelectedValue = x
      End If
      Catch ex As Exception
         MessageBox.Show(ex.ToString)
      End Try
End Sub
Danddba  Friday, September 16, 2005 1:13 PM

I don't think you can use a IsDBNull in a Int64 and what is the value of X when the error happen, is X really at 64 ? And there should be a check somewhere and validate that X is really in the values of the combobox, maybe there is no value 64 and what happend is the user print 345308530

ThE_lOtUs  Friday, September 16, 2005 3:06 PM

You can use google to search for other answers

Custom Search

More Threads

• Custom Controls...GDI to slow?
• Draw custom border around a control
• How do you turn 'redraw' off/on?
• Finding a Control in the GAC
• Validating in WinForms
• How to disassemble a Multipage TIFF into Separate Pages
• The type initializer for 'PublicVariables Module' threw an exception
• Supressing Print Dialog in MSHTML
• How to implement a Rocker Switch â€?3 way button?
• Scrollbar moved to display left,top edge of usercontrol when usercontrol too wide