This is a migrated thread and some comments may be shown as answers.

IsReadonlyBinding causes InvalidCastException when using ICustomTypeProvider items as a grid source

1 Answer 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 29 May 2013, 11:44 AM
Hi, I have the following case:

1. Item type is ICustomTypeProvider implementation. It has 2 dynamic properties: decimal Value and bool IsReadonly.
2. I'm setting a collection of such items as an ItemsSource for RadGridView.
3. I'm creating 1 GridViewDataColumn for Value property which has DataType set to decimal. IsReadonlyBinding for the column is bound to the IsReadonly property of the object.
4. When trying to edit cell, I'm getting the following exception:
(Further investigation shown that Unbox tries to cast value to the type of column (which is decimal) while value returned by IsReadonly is bool)

Specified cast is not valid.
System.Exception: Specified cast is not valid. ---> System.InvalidCastException: Specified cast is not valid.
   at Telerik.Windows.Data.Expressions.UnboxT`1.ValueField(Object value)
   at Telerik.Windows.Data.Expressions.CustomTypeProviderExtensions.Property[T](Object component, String propertyName)
   at Telerik.Windows.Data.Expressions.CustomTypeProviderExtensions.Property[T](ICustomTypeProvider typeProvider, String propertyName)
   at lambda_method(Closure , MetricRow )
   at Telerik.Windows.Data.FuncExtensions.<>c__DisplayClass1`2.<ToUntypedFunc>b__0(Object item)
   at Telerik.Windows.Controls.GridViewBoundColumnBase.EvaluateIsReadOnlyState(Object item)
   at Telerik.Windows.Controls.GridViewBoundColumnBase.CanEdit(Object item)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.BeginEdit(GridViewCell gridViewCell, RoutedEventArgs editEventArgs)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCellMouseDown(GridViewCell cell, MouseButtonEventArgs args)
   at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 29 May 2013, 01:11 PM
Hello,

I have answered the other support ticket.

Regards,
Rossen Hristov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Alexander
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or