[Mono-winforms-list] DataGridView: System.InvalidCastException, Value is not a convertible object

Stifu stifu at free.fr
Fri Jul 24 04:56:11 EDT 2009


Is this with Mono 2.4.x?
If so, it'd be nice if you could create a reduced test case and file a bug
report.


m0n0 wrote:
> 
> Hello there,
> 
> is isn't just a General question but I think it fit's best here...
> 
> I'm using WinForm and I add custom objects to a datagrid, after that I get
> this exception in the Paint routine of the datagrid: 
> 
> Unhandled Exception: System.InvalidCastException: Value is not a
> convertible object: MyNamespace.MyClass to System.String
>   at System.Convert.ToType (System.Object value, System.Type
> conversionType, IFormatProvider provider) [0x00000] 
>   at System.Convert.ChangeType (System.Object value, System.Type
> conversionType, IFormatProvider provider) [0x00000] 
>   at System.Windows.Forms.DataGridViewCell.get_FormattedValue () [0x00000] 
>   at System.Windows.Forms.DataGridViewRow.PaintCells
> (System.Drawing.Graphics graphics, Rectangle clipBounds, Rectangle
> rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean
> isFirstDisplayedRow, Boolean isLastVisibleRow, DataGridViewPaintParts
> paintParts) [0x00000] 
>   at System.Windows.Forms.DataGridViewRow.Paint (System.Drawing.Graphics
> graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex,
> DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean
> isLastVisibleRow) [0x00000] 
>   at System.Windows.Forms.DataGridView.OnPaint
> (System.Windows.Forms.PaintEventArgs e) [0x00000] 
>   at System.Windows.Forms.Control.WmPaint (System.Windows.Forms.Message&
> m) [0x00000] 
>   at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&
> m) [0x00000] 
>   at System.Windows.Forms.DataGridView.WndProc
> (System.Windows.Forms.Message& m) [0x00000] 
>   at System.Windows.Forms.Control+ControlWindowTarget.OnMessage
> (System.Windows.Forms.Message& m) [0x00000] 
>   at System.Windows.Forms.Control+ControlNativeWindow.WndProc
> (System.Windows.Forms.Message& m) [0x00000] 
>   at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg,
> IntPtr wParam, IntPtr lParam) [0x00000] 
>   at System.Windows.Forms.XplatUIX11.DispatchMessage
> (System.Windows.Forms.MSG& msg) [0x00000] 
>   at System.Windows.Forms.XplatUI.DispatchMessage
> (System.Windows.Forms.MSG& msg) [0x00000] 
>   at System.Windows.Forms.Application.RunLoop (Boolean Modal,
> System.Windows.Forms.ApplicationContext context) [0x00000] 
>   at System.Windows.Forms.Application.Run
> (System.Windows.Forms.ApplicationContext context) [0x00000] 
>   at System.Windows.Forms.Application.Run (System.Windows.Forms.Form
> mainForm) [0x00000] 
>   at Alias.Program.Main (System.String[] args) [0x00000]
> 
> i never saw such a problem with MS .Net, but I had overloaded the ToString
> method to show what I want in the datagrid: 
> 
> public override string ToString()
> {
>   return ("What I want!");                           
> }
> that worked well with M$... 
> 
> now mono makes problem, does anyone of you have a workaround? 
> 
> I also implemented the 
> public static implicit operator String( MyClass t )
> {
>  return t.ToString();
> } 
> to get around the problem, but that doesn't work, too. 
> 

-- 
View this message in context: http://www.nabble.com/DataGridView%3A-System.InvalidCastException%2C-Value-is-not-a-convertible-object-tp24639939p24641017.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.



More information about the Mono-winforms-list mailing list