Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello friends,
this is my code.
XML
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
       {
           comp.CLASSID = Convert.ToInt32(comboBox2.SelectedValue.ToString());
           comp.ACADAMICYEAR = textBox1.Text;
           List<string> result = inter.getSectionforsetting(comp);
           comboBox3.DataSource = result;
       }



the error is
Input string was not in a correct format.

but
when i enter the above code in combobox2_leave event it actually run without any error.
what is the error
Posted
Comments
Sanjay K. Gupta 2-Jan-13 8:11am    
Reason :- value of "comboBox2.SelectedValue.ToString()" is non-numeric.
Rest is up to you.
baskaran chellasamy 2-Jan-13 8:20am    
if it is non numeric then how can it accept numeric value in comboboxleave event
Alan N 2-Jan-13 12:25pm    
First step is accepting that the error message is correct. Second is finding out what the actual value is by viewing it with the debugger. If you don't understand why the string has that value then ask by editing your questionto include the new information.
DR Delphi 6-Jan-13 12:21pm    
Please share what the error message is.. we are not mind readers and cannot possible know what the value of the comp.CLASSID = Convert.ToInt32(comboBox2.SelectedValue.ToString()); is what if you have the value of the SelectedValue.ToString() as 'ABC' ? it will ERROR.. so personally I would would either run a prior check to make sure that the value being selected is numeric also you can look at the Parse() Method..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900