Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hello friends,
this is my code.
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 2-Jan-13 1:51am
Comments
Sanjay K. Gupta at 2-Jan-13 8:11am
   
Reason :- value of "comboBox2.SelectedValue.ToString()" is non-numeric.
Rest is up to you.
baskaran chellasamy at 2-Jan-13 8:20am
   
if it is non numeric then how can it accept numeric value in comboboxleave event
Alan N at 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 at 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)

  Print Answers RSS
0 OriginalGriff 428
1 Sergey Alexandrovich Kryukov 283
2 PhilLenoir 115
3 RajeeshMenoth 110
4 Peter Leow 100
0 Sergey Alexandrovich Kryukov 6,465
1 OriginalGriff 5,926
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,540


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100