Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - ObjectDisposedException on second use

Reply
 
Old 09-10-2008   #1 (permalink)
LLcoolQ


 
 

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(Control
value)
at System.Windows.Forms.Control.set_Parent(Control value)
at
DataGridViewNumericUpDownElements.DataGridViewNumericUpDownCell.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\DataGridViewNumericUpDownElements
\DataGridViewNumericUpDownCell.cs:line 575
at System.Windows.Forms.DataGridViewCell.PaintInternal(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.DataGridViewCellPaintingEventArgs.PaintContent(Rectangle
clipBounds)
at
ComponentFactory.Krypton.Toolkit.KryptonDataGridView.OnCellPainting(DataGridViewCellPaintingEventArgs
e)
at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics
graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex,
DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.PaintCells(Graphics
graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex,
DataGridViewElementStates rowState, Boolean isFirstDisplayedRow,
Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.Paint(Graphics
graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex,
DataGridViewElementStates rowState, Boolean isFirstDisplayedRow,
Boolean isLastVisibleRow)
at System.Windows.Forms.DataGridView.PaintRows(Graphics g,
Rectangle boundingRect, Rectangle clipRect, Boolean
singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.PaintGrid(Graphics g,
Rectangle gridBounds, Rectangle clipRect, Boolean
singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)

It points to this line of code

paintingNumericUpDown.TextAlign =
DataGridViewNumericUpDownCell.TranslateAlignment(cellStyle.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.









My System SpecsSystem Spec
Reply

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46