ListBox Bug?

  • Thread starter Thread starter Jason Lines
  • Start date Start date
J

Jason Lines

I have a Form which contains a ListBox.

I have assigned a EventHandler to the DoubleClick event of the ListBox

Within the event handler I am disposing the form.

After closing the form I get the following exception

*this functionality works fine using a Button.Click

(source code follows)


Unhandled Exception: System.ObjectDisposedException: Cannot access a
disposed object named "ListBox".
Object name: "ListBox".

at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.PointToScreen(Point p)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ListBox.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)







this.lstSelect.DoubleClick += new
System.EventHandler(this.lstSelect_DoubleClicked);

private void lstSelect_DoubleClicked(object sender, System.EventArgs
e)
{
this.Hide();
this.Dispose();
}


thanks
Jason
 
Back
Top