• Advertisement
Sign in to follow this  

List Box Issues

This topic is 1982 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey I've ran into another issue where I don't know what's going on. I'm still following the tutorials I mentioned in a previous post. I'm making a small program that uses for loops to cycle through numbers. I am using a listbox to display the numbers when the program is executed. I have followed the tutorial as it stated but I'm getting an error when I try to run my program.

My code is as follows, as well as the error message that appears:

private void button1_Click(object sender, EventArgs e)
{
int loopStart;
int loopEnd;
int answer = 0;
loopStart = int.Parse(textBox1.Text);
loopEnd = int.Parse(textBox2.Text);
for (int i = loopStart; i > loopEnd; i++)
{
answer = answer + i;
listBox1.Items.Add(answer.ToString());
}

When I run it I get this:

Error 1 'Loops.Form1' does not contain a definition for 'listBox1_SelectedIndexChanged' and no extension method 'listBox1_SelectedIndexChanged' accepting a first argument of type 'Loops.Form1' could be found (are you missing a using directive or an assembly reference?)

I really have no idea what's happening I will attach[attachment=10715:Loops.zip] my program to this post. Any help is greatly appreciated :)

Share this post


Link to post
Share on other sites
Advertisement
The error occurs in this line in the "Form1.Designer.cs" file:

this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);


I'm guessing you registered a handler for the SelectedIndexChanged event in the designer at one point but deleted the automatically-generated method in the "Form1.cs" file. The code-behind file generated by the designer still tries to use the missing method however. You can simply double-click on the error message and delete the line to get rid of the error.

Share this post


Link to post
Share on other sites
Thank you for the help :) I feel stupid not knowing what half of this stuff is/means D:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement