By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 974 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Cannot access to disposed oject.

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.