469,646 Members | 1,591 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

ObjectDisposedException on second use

I have created a DataGridViewNumericUpDownColumn using this from MSDN:

http://msdn.microsoft.com/en-us/libr...81(vs.80).aspx

I build my grids at run-time, here is the code for adding the column:

Dim colQtyShipped As New DataGridViewNumericUpDownColumn
With colQtyShipped
.Increment = 1
.Minimum = 0
.Maximum = 250
.DataPropertyName = "QuantityShipped"
.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
.HeaderText = "Packed"
.Name = "QuantityShipped"
.[ReadOnly] = False
.Visible = True
.MinimumWidth = 50
.Width = 50
End With
itemGrid.Columns.Add(colQtyShipped)

The first time i open a form, all works well. The column displays,
the arrows work fine, the data binding works fine.

As soon as i close the form and open a new instance, I get this error:

Cannot access a disposed object
Object name: 'NumericUpDown'.

System.ObjectDisposedException was unhandled by user code
Message="Cannot access a disposed object.\r\nObject name:
'NumericUpDown'."
Source="System.Windows.Forms"
ObjectName="NumericUpDown"
StackTrace:
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add (Control
value)
at System.Windows.Forms.Control.set_ParentInternal(Co ntrol
value)
at System.Windows.Forms.Control.set_Parent(Control value)
at
DataGridViewNumericUpDownElements.DataGridViewNume ricUpDownCell.Paint(Graphics
graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex,
DataGridViewElementStates cellState, Object value, Object
formattedValue, String errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts) in C:\Dotnet\Examples
\DataGridViewNumericUpDown\DataGridViewNumericUpDo wnElements
\DataGridViewNumericUpDownCell.cs:line 575
at System.Windows.Forms.DataGridViewCell.PaintInterna l(Graphics
graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex,
DataGridViewElementStates cellState, Object value, Object
formattedValue, String errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
at
System.Windows.Forms.DataGridViewCellPaintingEvent Args.PaintContent(Rectangle
clipBounds)
at
ComponentFactory.Krypton.Toolkit.KryptonDataGridVi ew.OnCellPainting(DataGridViewCellPaintingEventArg s
e)
at System.Windows.Forms.DataGridViewCell.PaintWork(Gr aphics
graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex,
DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.PaintCells(Gr aphics
graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex,
DataGridViewElementStates rowState, Boolean isFirstDisplayedRow,
Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.Paint(Graphic s
graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex,
DataGridViewElementStates rowState, Boolean isFirstDisplayedRow,
Boolean isLastVisibleRow)
at System.Windows.Forms.DataGridView.PaintRows(Graphi cs g,
Rectangle boundingRect, Rectangle clipRect, Boolean
singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.PaintGrid(Graphi cs g,
Rectangle gridBounds, Rectangle clipRect, Boolean
singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.OnPaint(PaintEve ntArgs e)

It points to this line of code

paintingNumericUpDown.TextAlign =
DataGridViewNumericUpDownCell.TranslateAlignment(c ellStyle.Alignment);

in class DataGridViewNumericUpDownCell
Really not sure what is causing this. i am not trying to reuse an
object, trying to create a new one.


Sep 10 '08 #1
2 3023
If i leave the first form that used this open, i can open and close
forms forever. as soon as i close the form that it was first used on,
the ObjectDisposedException is thrown. I can work around this for now
by creating an invisible instance of this at app startup, but will dig
in and figure out how to get around this

Sep 10 '08 #2
problem solved

http://forums.microsoft.com/forums/s...36239&siteid=1

thanx for your help
Sep 10 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Kevin Smith | last post: by
reply views Thread by TomPel | last post: by
reply views Thread by Richard Blewett [DevelopMentor] | last post: by
reply views Thread by Darrell Wesley | last post: by
reply views Thread by *shame-faced* via DotNetMonster.com | last post: by
2 posts views Thread by Bernard Borsu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.