PC Review


Reply
Thread Tools Rate Thread

BUG in VB .NET 2003?

 
 
Andy
Guest
Posts: n/a
 
      3rd Oct 2003
Hi to All,

I found the following issue, is this a bug?

Create a new project and, in the main form, add a listbox with a few sample
items. In the DoubleClick event of the listbox, add:

Me.Dispose()

Then run the project, double click on an item in the listbox to close the
window and then an Exception occurs.

What is the problem? I would like to close the form by double clicking on
the listbox...
Thank you,

Andy



 
Reply With Quote
 
 
 
 
msnews.microsoft.com
Guest
Posts: n/a
 
      3rd Oct 2003
Not a bug. Do not Dispose() in a click event. I am not real Windows Forms
savvy, but there is a way to close the form. You can Dispose() afterward,
but you have to make sure there is a Dispose() method coded for the class
you are disposing. Not sure if a form class has a Dispose() method without
adding IDisposable. Either way, you do not want to Dispose() the object in
the object.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
"Andy" <(E-Mail Removed)> wrote in message
news:9Fhfb.219805$(E-Mail Removed)...
> Hi to All,
>
> I found the following issue, is this a bug?
>
> Create a new project and, in the main form, add a listbox with a few

sample
> items. In the DoubleClick event of the listbox, add:
>
> Me.Dispose()
>
> Then run the project, double click on an item in the listbox to close the
> window and then an Exception occurs.
>
> What is the problem? I would like to close the form by double clicking on
> the listbox...
> Thank you,
>
> Andy
>
>
>



 
Reply With Quote
 
steve
Guest
Posts: n/a
 
      3rd Oct 2003
what's the exception?


"Andy" <(E-Mail Removed)> wrote in message
news:9Fhfb.219805$(E-Mail Removed)...
> Hi to All,
>
> I found the following issue, is this a bug?
>
> Create a new project and, in the main form, add a listbox with a few

sample
> items. In the DoubleClick event of the listbox, add:
>
> Me.Dispose()
>
> Then run the project, double click on an item in the listbox to close the
> window and then an Exception occurs.
>
> What is the problem? I would like to close the form by double clicking on
> the listbox...
> Thank you,
>
> Andy
>
>
>



 
Reply With Quote
 
Patrick Steele [MVP]
Guest
Posts: n/a
 
      3rd Oct 2003
In article <9Fhfb.219805$(E-Mail Removed)>, (E-Mail Removed)
says...
> What is the problem? I would like to close the form by double clicking on
> the listbox...


Try Me.Close().

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      3rd Oct 2003
Hi Andy,
You are not closing it, you are killing it, look at the message from Patrick
Cor


 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      3rd Oct 2003
Something like "Cannot access disposed object named "ListBox"

Andy


"steve" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed)...
> what's the exception?
>




 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      3rd Oct 2003
The same Exception happens also with "Me.Close()"...

Andy


"Patrick Steele [MVP]" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed)...
> In article <9Fhfb.219805$(E-Mail Removed)>, (E-Mail Removed)
> says...
> > What is the problem? I would like to close the form by double clicking

on
> > the listbox...

>
> Try Me.Close().




 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      3rd Oct 2003
But I need to close (unload) the form from a double click event...

I searched with google and, strangely, in the first version of VB6 there was
a bug: if you tried to unload the form from a listbox's doubleclick event, a
GPF occurred. This was solved in later SP. What coincidence!

Andy

"msnews.microsoft.com" <(E-Mail Removed)> ha scritto nel
messaggio news:#(E-Mail Removed)...
> Not a bug. Do not Dispose() in a click event. I am not real Windows Forms
> savvy, but there is a way to close the form. You can Dispose() afterward,
> but you have to make sure there is a Dispose() method coded for the class
> you are disposing. Not sure if a form class has a Dispose() method without
> adding IDisposable. Either way, you do not want to Dispose() the object in
> the object.




 
Reply With Quote
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      3rd Oct 2003
The point I am getting at is Dispose() is not the proper way to destroy an
object from inside the object. I would aim for close, but you are stating
you are getting the same message there. I do not understand the need to
close from doubleclick rather than set up a close button, but each app is
different.

This causes no problems for me in VS.NET 2003:

Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles ListBox1.DoubleClick
Try
Me.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
'Finally
' MessageBox.Show("In Finally")
End Try
End Sub

unless I uncomment the Finally. This makes sense, as I have closed the form
by this point in time. I cannot run through debug on this machine, as I need
to catch someone to get permissions (aaarrrggghhhh!!!).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
"Andy" <(E-Mail Removed)> wrote in message
news:fWifb.220436$(E-Mail Removed)...
> But I need to close (unload) the form from a double click event...
>
> I searched with google and, strangely, in the first version of VB6 there

was
> a bug: if you tried to unload the form from a listbox's doubleclick event,

a
> GPF occurred. This was solved in later SP. What coincidence!
>
> Andy
>
> "msnews.microsoft.com" <(E-Mail Removed)> ha scritto nel
> messaggio news:#(E-Mail Removed)...
> > Not a bug. Do not Dispose() in a click event. I am not real Windows

Forms
> > savvy, but there is a way to close the form. You can Dispose()

afterward,
> > but you have to make sure there is a Dispose() method coded for the

class
> > you are disposing. Not sure if a form class has a Dispose() method

without
> > adding IDisposable. Either way, you do not want to Dispose() the object

in
> > the object.

>
>
>



 
Reply With Quote
 
CJ Taylor
Guest
Posts: n/a
 
      3rd Oct 2003
Try adding

Application.DoEvents before the close method...

I do'nt know if it will work, but dispose is for garbage collection, and not
the right way to shut down a window. Close calls dispose through Finalize I
believe.


"Andy" <(E-Mail Removed)> wrote in message
news:QTifb.220418$(E-Mail Removed)...
> The same Exception happens also with "Me.Close()"...
>
> Andy
>
>
> "Patrick Steele [MVP]" <(E-Mail Removed)> ha scritto nel messaggio
> news:(E-Mail Removed)...
> > In article <9Fhfb.219805$(E-Mail Removed)>, (E-Mail Removed)
> > says...
> > > What is the problem? I would like to close the form by double clicking

> on
> > > the listbox...

> >
> > Try Me.Close().

>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does BCM 2003 work with Outlook 2003 and Exchange 2003 =?Utf-8?B?bGFycnk=?= Microsoft Outlook BCM 0 30th Jan 2007 04:43 PM
Outlook 2003 Cant send e-mail from Excel 2003 or word 2003 =?Utf-8?B?QW5keQ==?= Microsoft Word Document Management 7 25th Oct 2006 04:33 AM
Does Outlook Standard 2003 have excel 2003 and Word 2003? =?Utf-8?B?ZGVuZWVu?= Microsoft Outlook Discussion 2 6th Sep 2006 01:16 AM
outlook 2003 on sbs server 2003 using exchange 2003 =?Utf-8?B?SmVubiBAIEEgRHJlYW0gQ2F0Y2hlcg==?= Microsoft Outlook Discussion 1 25th Mar 2006 03:44 PM
Outlook 2003 (Exchange 2003) Calendar Requests to Outlook 2003 (PO =?Utf-8?B?Sm9lIFNjaHVybWFu?= Microsoft Outlook Calendar 0 23rd Nov 2004 08:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:19 AM.