473,387 Members | 1,455 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,387 software developers and data experts.

Disposed object

HI , I posted the problem in this newsgroup before. And I
couldn't solve it completely.

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()
Dim frm2 as new form2()
frm2.show()
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 will be appreciated.
Thanks
Nov 20 '05 #1
1 2066
I'm sorry for the typo I made in above post.
(In class Form1)
Dim frm2 as new form2

should be changed to be

frm2 = new Form2
-----Original Message-----
HI , I posted the problem in this newsgroup before. And Icouldn't solve it completely.

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.DataSo urce,
DataGridBTerm.DataMember)
Dim datarw As DataRow = CType(bm.Current,
DataRowView).Row
//click an item
If sender.currentcell.columnnumber = 0 Then
Me.close()
Dim frm2 as new form2() (I'm sorry, it should be
frm2 = new Form2
)

frm2.show()
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 will be appreciated.
Thanks
.

Nov 20 '05 #2

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

Similar topics

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()
9
by: David Sworder | last post by:
Hi, I have a form that displays data (is that vague enough for you?). The data comes in on a thread-pool thread. Since the thread pool thread is not the same as the UI thread, the callback...
6
by: Jim H | last post by:
I have a class object that creates and uses a System.Threading.Timer. In the destructor for my class I cancel the timer using timer.Change(infinite, infinite) then I call timer.Dispose() to clean...
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...
6
by: SamSpade | last post by:
Public Function PicCreateGraphics() As Graphics 'Client should dispose this PicCreateGraphics = Graphics.FromImage(mDocumentImage) mPicCreateGraphicsSaved = PicCreateGraphics 'Saved so I can...
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...
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
31
by: Zytan | last post by:
There is no IsDisposed() method. I could just access it, and catch ObjectDisposedException, but that seems ugly. Zytan
2
by: BillE | last post by:
Using vb.net 2008 windows forms. How can a form which has been closed and disposed still attempt to handle a custom event? I have a form which inherits from a base form class. The base...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.