Click here to Skip to main content
12,898,663 members (58,089 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# 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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2017
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