TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Katie B
NA
66
18.1k
C# - Input string was not in correct format!
Apr 14 2013 1:07 PM
Evening All,
I'm trying to get this bit of code to take the numbers from the list box and add them in the label named ucaspoints. But when I write this code:
private void btnAdd_Click(object sender, EventArgs e)
{
int totalpoints = 0;
string item = lstboxGrades.SelectedItem.ToString();
lstboxeducation.Items.Add(item);
totalpoints = int.Parse(lstboxeducation.Text) + totalpoints;
ucaspoints.Text = totalpoints.ToString();
}
It runs without error, but only displays the numbers in the list box rather than adding them. Ive tried adapting this to:
private void btnAdd_Click(object sender, EventArgs e)
{
int totalpoints = 0;
string item = lstboxGrades.SelectedItem.ToString();
lstboxeducation.Items.Add(item);
totalpoints =
Convert.ToInt32(lstboxeducation.Text) + totalpoints;
ucaspoints.Text = totalpoints.ToString();
}
Swapping the int.Parse to Convert.ToInt32 but then i receive a run time error stating that the "Input string is not in the correct format" (on the line in bold). Ive tried putting break points in and with the int.Parse it runs through it no problem, but it will stop at the convert.toint32 and give the above error.
Any advice would be great. Thanks
Reply
Answers (
2
)
how to refresh the dataset
Object reference not set to an instance of an object.