467,188 Members | 1,435 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,188 developers. It's quick & easy.

ListBox DoubleClick -> Form.Close error

I am using VS.NET 2003 and am having an interesting issue with a Listbox control. Essentially, I have a form with a listbox on it. In the listbox doubleclick event I would like to do some processing and then close the form. However, I receive an error (Cannot access a disposed object named "ListBox".) after my doubleclick code has processed.

/* ***************************
private void listBox1_DoubleClick(object sender, System.EventArgs e)
{
this.Close();
}
****************************/

To reproduce, create a form, drop a listbox on it, assign the doubleclick event and put "this.Close();" in the handler. Does anyone know if there is a fix to this issue? There are workarounds, best I've seen so far is:
/****************************
private void listBox1_DoubleClick(object sender, System.EventArgs e)
{
this.BeginInvoke( new EventHandler( CloseForm ) );
}

private void CloseForm( Object sender, EventArgs e )
{
this.Close();
}
***********************************/

I think this must be an error in how the message processing is handled within the list box control itself?

Thanks,
Joe
Nov 16 '05 #1
  • viewed: 3388
Share:
2 Replies
Joe,

I tried a sample like you described. Form closes properly after doubleclick
in listbox. No issues at all.

--
Shak
(Houston)


"JoeHenrich" <Jo********@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
I am using VS.NET 2003 and am having an interesting issue with a Listbox control. Essentially, I have a form with a listbox on it. In the listbox
doubleclick event I would like to do some processing and then close the
form. However, I receive an error (Cannot access a disposed object named
"ListBox".) after my doubleclick code has processed.
/* ***************************
private void listBox1_DoubleClick(object sender, System.EventArgs e)
{
this.Close();
}
****************************/

To reproduce, create a form, drop a listbox on it, assign the doubleclick event and put "this.Close();" in the handler. Does anyone know if there is
a fix to this issue? There are workarounds, best I've seen so far is: /****************************
private void listBox1_DoubleClick(object sender, System.EventArgs e)
{
this.BeginInvoke( new EventHandler( CloseForm ) );
}

private void CloseForm( Object sender, EventArgs e )
{
this.Close();
}
***********************************/

I think this must be an error in how the message processing is handled within the list box control itself?
Thanks,
Joe

Nov 16 '05 #2
I am using .VS.NET 2003.

code is pretty simple.

1. Created new c# project and it loaded default form "Form1"
2. I added listbox with default name listBox1
3.Added double click event
4. Added one line of code in that event
this.Close()

When i double clicked on listbox everything works fine. Form closed properly
without any errors.

--
Shak
(Houston)


"JoeHenrich" <Jo********@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
Can you provide me the code for what your tried? And, what version of ..NET you are running? Thanks

"Shakir Hussain" wrote:
Joe,

I tried a sample like you described. Form closes properly after doubleclick in listbox. No issues at all.

--
Shak
(Houston)


"JoeHenrich" <Jo********@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
I am using VS.NET 2003 and am having an interesting issue with a
Listbox control. Essentially, I have a form with a listbox on it. In the listbox doubleclick event I would like to do some processing and then close the
form. However, I receive an error (Cannot access a disposed object named "ListBox".) after my doubleclick code has processed.

/* ***************************
private void listBox1_DoubleClick(object sender, System.EventArgs e)
{
this.Close();
}
****************************/

To reproduce, create a form, drop a listbox on it, assign the
doubleclick event and put "this.Close();" in the handler. Does anyone know if there is a fix to this issue? There are workarounds, best I've seen so far is:
/****************************
private void listBox1_DoubleClick(object sender, System.EventArgs e)
{
this.BeginInvoke( new EventHandler( CloseForm ) );
}

private void CloseForm( Object sender, EventArgs e )
{
this.Close();
}
***********************************/

I think this must be an error in how the message processing is handled

within the list box control itself?

Thanks,
Joe


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike | last post: by
1 post views Thread by Buddy Ackerman | last post: by
3 posts views Thread by thomasp@msala.net | last post: by
1 post views Thread by =?Utf-8?B?cGVsZWdrMQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.