473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Cannot access to disposed oject.

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 click a grid item in datagrid1, I wanna show
form2. In my code, I achieved that with:

Public class Form1
Inherits System.Windows.Forms.Form
DIm frm2 as Form2
...
Private sub Datagrid1_currentCellChanged(ByVal sender
As Object, ByVal e As EventArgs)
Dim bm As BindingManagerBase =
DataGridBTerm.BindingContext(DataGridBTerm.DataSou rce,
DataGridBTerm.DataMember)
Dim datarw As DataRow = CType(bm.Current,
DataRowView).Row
//click an item
If sender.currentcell.columnnumber = 0 Then
Me.close()
frm2 = new form2
End sub
.....
End Class

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"
Here is the debug information:
************** Exception Text **************
System.ObjectDisposedException: Cannot access a disposed
object named "DataGridTextBox".
Object name: "DataGridTextBox".
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.TextBoxBase.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.TextBox.GetLength()
at System.Windows.Forms.TextBoxBase.set_SelectionStar t
(Int32 value)
at System.Windows.Forms.TextBox.SelectInternal(Int32
start, Int32 length)
at System.Windows.Forms.TextBoxBase.SelectAll()
at System.Windows.Forms.DataGridTextBoxColumn.Edit
(CurrencyManager source, Int32 rowNum, Rectangle bounds,
Boolean readOnly, String instantText, Boolean
cellIsVisible)
at System.Windows.Forms.DataGrid.Edit(String
instantText)
at System.Windows.Forms.DataGrid.Edit()
at System.Windows.Forms.DataGrid.set_CurrentCell
(DataGridCell value)
at System.Windows.Forms.DataGrid.OnMouseDown
(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message&
m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage
(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc
(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Any help on that will be appreciated.
Thanks!

Nov 20 '05 #1
3 3380
Cor
Hi Tracey,

Can this be the error, just a guess
Me.close()
frm2 = new form2


For me it looks strange

Close the class and when it is closed call with that closed class another
class?

Maybe I am wrong, but I find it looking strange?

Cor

Nov 20 '05 #2
Hi Tracey,
Me.close()
This is the beast. You need to change it to 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:03****************************@phx.gbl... 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 click a grid item in datagrid1, I wanna show
form2. In my code, I achieved that with:

Public class Form1
Inherits System.Windows.Forms.Form
DIm frm2 as Form2
...
Private sub Datagrid1_currentCellChanged(ByVal sender
As Object, ByVal e As EventArgs)
Dim bm As BindingManagerBase =
DataGridBTerm.BindingContext(DataGridBTerm.DataSou rce,
DataGridBTerm.DataMember)
Dim datarw As DataRow = CType(bm.Current,
DataRowView).Row
//click an item
If sender.currentcell.columnnumber = 0 Then
Me.close()
frm2 = new form2
End sub
....
End Class

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"
Here is the debug information:
************** Exception Text **************
System.ObjectDisposedException: Cannot access a disposed
object named "DataGridTextBox".
Object name: "DataGridTextBox".
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.TextBoxBase.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.TextBox.GetLength()
at System.Windows.Forms.TextBoxBase.set_SelectionStar t
(Int32 value)
at System.Windows.Forms.TextBox.SelectInternal(Int32
start, Int32 length)
at System.Windows.Forms.TextBoxBase.SelectAll()
at System.Windows.Forms.DataGridTextBoxColumn.Edit
(CurrencyManager source, Int32 rowNum, Rectangle bounds,
Boolean readOnly, String instantText, Boolean
cellIsVisible)
at System.Windows.Forms.DataGrid.Edit(String
instantText)
at System.Windows.Forms.DataGrid.Edit()
at System.Windows.Forms.DataGrid.set_CurrentCell
(DataGridCell value)
at System.Windows.Forms.DataGrid.OnMouseDown
(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message&
m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage
(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc
(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Any help on that will be appreciated.
Thanks!

Nov 20 '05 #3
"Tracey" <an*******@discussions.microsoft.com> schrieb
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 click a grid item in datagrid1, I wanna show
form2. In my code, I achieved that with:

Public class Form1
Inherits System.Windows.Forms.Form
DIm frm2 as Form2
...
Private sub Datagrid1_currentCellChanged(ByVal sender
As Object, ByVal e As EventArgs)
Dim bm As BindingManagerBase =
DataGridBTerm.BindingContext(DataGridBTerm.DataSou rce,
DataGridBTerm.DataMember)
Dim datarw As DataRow = CType(bm.Current,
DataRowView).Row
//click an item
If sender.currentcell.columnnumber = 0 Then
Me.close()
frm2 = new form2
End sub
....
End Class

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"
[...]


Just a thought and an attempt: add a Timer (enabled=false) to your Form.
Instead of closing the Form in the currentCellChanged event handler, _only_
enable the timer. In the timer's tick event, close the Form. Maybe the code
raising the event is trying to access the Form after you've closed it. The
Timer is a way to find this out. AFAIR there was a similar problem in the
past.
--
Armin

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()
0
by: Mackuack | last post by:
Hello everybody i have the following code to access an application via https: --------------------------------------------- System.Net.ServicePointManager.CertificatePolicy = new...
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...
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...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.