-
Problem with Events
Hey all, i am using a small form containing a listbox.
Now what I want to do is if the user double clicks an Item in the listbox, some code will happen and then the form closes.
So I added the doubleClick Event and tried
this.close();
Calling the close method I guess call the dispose method right?
Now I always get an Exception in the dipose method saying Object listbox cannot be accessed.
So, how can close the form from this event?
Thanks Stephan
-
I need code to play wih it on my computer to see what is wrong.
-
Well all you need are two forms. The first one just opens the second one. On the second form add a listbox to it.
then in your private void InitializeComponent()
add this:
Code:
this.listbox.DoubleClick+= new System.EventHandler(this.ListBox_DoubleClick);
and then add the EventHandler:
Code:
private void ListBox_DoubleClick(object sender, EventArgs e)
{
this.Close();
}
Stephan