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 answer = 0;
loopStart = int.Parse(textBox1.Text);
loopEnd = int.Parse(textBox2.Text);
for (int i = loopStart; i > loopEnd; i++)
answer = answer + i;
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 attachLoops.zip36.93KB40 downloads my program to this post. Any help is greatly appreciated
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.