lothos12345 Posted March 22, 2005 Posted March 22, 2005 At the following code line it is giving me an invalid cast exception not sure why. Keeping in mind that option strict is on. Any given would be greatly appreiciated. Dim tindex as integer tindex = Convert.ToInt32(ComboBox4.SelectedValue) Quote
betrl8thanever Posted March 22, 2005 Posted March 22, 2005 Its going to depend a lot on where your code is actually executing. You might try If (Me.ComboBox4.SelectedIndex <> -1) Then Dim tindex as Integer = CInt(Me.ComboBox4.SelectedItem.ToString()) End If Quote "In the immortal words of Socrates, who said "' I drank what?!'"
lothos12345 Posted March 22, 2005 Author Posted March 22, 2005 Did not work No unforunately it did not work, it through the same error. Quote
Administrators PlausiblyDamp Posted March 22, 2005 Administrators Posted March 22, 2005 If you step through the code in the debugger what is the value of SelectedIndex when the error occurs? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
lothos12345 Posted March 22, 2005 Author Posted March 22, 2005 SelectedIndex The selectedindex value is 0. Because it loads the DisplayMembers of the Combobox on the initial load. Quote
Administrators PlausiblyDamp Posted March 22, 2005 Administrators Posted March 22, 2005 Sorry - I meant what is the value for the SelectedValue? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders snarfblam Posted March 23, 2005 Leaders Posted March 23, 2005 Is there a SelectedValue property? Or are you referring to SelectedItem? Like PlausiblyDamp said, check the value of SelectedItem (or SelectedItem.ToString). Could be that it is nothing or an invalid string. Check either that (.SelectedIndex <> -1) or that (Not .SelectedItem Is Nothing). Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.