473,473 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Cannot access disposed object

Hi, there
I met a very wierd problem. My startup form say Form1 has
a datagrid say datagrid1, when I click an item in
datagrid1, I wanna show form2. In my code, I achieved
that with:
private sub Datagrid1_currentCellChanged(ByVal sender As
Object, ByVal e As EventArgs)
....
Me.close()
dim frm2 as new form2()
frm2.show()
end sub

In form2 there is also a datagrid called datagrid2.

My problem is when I click the item in form1,form2 showed
up but with an error massage window says:
Cannot access disposed object named "DataGridTextBox"
Object name: "DataGridTextBox"
The problem is I didn't have any datagrid named with
datagridTextBox. Can someone provide some advice ?
Thanks a lot!
Nov 20 '05 #1
3 1649
Hi, calling Me.Close will dispose the form, and put it out for garbage
collection. Use Me.Hide instead.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Tracey" <an*******@discussions.microsoft.com> wrote in message
news:0a****************************@phx.gbl...
Hi, there
I met a very wierd problem. My startup form say Form1 has
a datagrid say datagrid1, when I click an item in
datagrid1, I wanna show form2. In my code, I achieved
that with:
private sub Datagrid1_currentCellChanged(ByVal sender As
Object, ByVal e As EventArgs)
...
Me.close()
dim frm2 as new form2()
frm2.show()
end sub

In form2 there is also a datagrid called datagrid2.

My problem is when I click the item in form1,form2 showed
up but with an error massage window says:
Cannot access disposed object named "DataGridTextBox"
Object name: "DataGridTextBox"
The problem is I didn't have any datagrid named with
datagridTextBox. Can someone provide some advice ?
Thanks a lot!

Nov 20 '05 #2
Hi Tracey,

I think it's likely that when you call Me.Close, it disposes of Me along
with all the controls on it, including Datagrid1. DataGridTextbox is probably
a control associated with DataGrid1 and it will be disposed of as well.

The problem is, this is happening inside an eventhandler for the DataGrid
and it expects, when it returns, to find itself with a live and valid
DataGrid. It doesn't, so Bang!

See if taking out the Me.Close makes the problem go away. If it does,
you'll hav to arrange a different way to close the form. One idea is to start
a timer with a very short delay and close the form when it goes off.

Another. It might be possible to pass Me to frm2 in the form2 constructor
and have <it> close form1 but it depends on whether closing another form is
done immediately or via its message queue, and I'm not certain.

Regards,
Fergus
Nov 20 '05 #3
Thank you so much!!!
-----Original Message-----
Hi Tracey,

I think it's likely that when you call Me.Close, it disposes of Me alongwith all the controls on it, including Datagrid1. DataGridTextbox is probablya control associated with DataGrid1 and it will be disposed of as well.
The problem is, this is happening inside an eventhandler for the DataGridand it expects, when it returns, to find itself with a live and validDataGrid. It doesn't, so Bang!

See if taking out the Me.Close makes the problem go away. If it does,you'll hav to arrange a different way to close the form. One idea is to starta timer with a very short delay and close the form when it goes off.
Another. It might be possible to pass Me to frm2 in the form2 constructorand have <it> close form1 but it depends on whether closing another form isdone immediately or via its message queue, and I'm not certain.
Regards,
Fergus
.

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: salih ataoz | last post by:
i close a form and i want to open it again it show me Cannot access a disposed object at vb6 this is ok at comman1_click form1.show
7
by: Ryan Park | last post by:
Hi, //SITUATION I got a panel control that hold a certain position on a form. Every controls or UIs are on this panel. At certain situation, I called dispose() method of this panel control...
5
by: D Witherspoon | last post by:
I use the following code to open up a form. ------------------------------------------------------- If fImage Is Nothing Then fImage = New frmImage End If fImage.Show()
5
by: theinvisibleGhost | last post by:
I'm having a problem that occurs at random in my app. I get an exception "Cannot Access a disposed object" In MSCorLib when calling boolean Change (int32, int32) Stack trace reveals...
5
by: mthgk | last post by:
I have a C# MDI app. The child forms do alot of work, so this work is perfomed on a different thread created using ThreadPool.QueueUserWorkItem(). Because the status of the work is important to...
3
by: Tracey | last post by:
sorry I post this problem again. I have to stop my work to fix the problem. I'm doing a multi form application(Not a MDI one). My startup form say Form1 has a datagrid say datagrid1, when I...
2
by: Rajat Tandon | last post by:
Hi, I have a grid which is continuously updating by the data from a external event. When I close the form on which the grid is placed, then it gives the error message ... "Can not access a...
1
by: Amit Dedhia | last post by:
Hi I am having problem working with Timers in C++/CLI (the .NET version of C++) I have an application which has several forms with pictureBox controls on it. There is a background timer...
0
by: sdanda | last post by:
Hai i am working on vb.net. In my application I created four forms.Those are first.vb,f1.vb,f2.vb and f3.vb In firstvb I added 3 checkboxes and a "display" button.The 3 checkboxes are used to...
4
JustRun
by: JustRun | last post by:
Hi All, I'm developing a windows desktop solution using VC# , I deal with my database using Dataset. My Problem that i'm trying to call a Form to display a confirmation message after every...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.