How to convert a built-in type to a custom type?

Hello,

I have a property grid with a nested property, generated by a custom class. When I modify a value I get the error in the Visual Studio output window:

System.Windows.Data Error: 23 : Cannot convert '6' from type 'String' to type 'PropertyGrid_CustomEditor.Levels' for 'en-US' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: TypeConverter cannot convert from System.String.
   at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
   at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'
System.Windows.Data Error: 7 : ConvertBack cannot convert value '6' (type 'String'). BindingExpression:Path=VLevels; DataItem='Employee' (HashCode=15832433); target element is 'PropertyItem' (HashCode=38893755); target property is 'Value' (type 'Object') NotSupportedException:'System.NotSupportedException: TypeConverter cannot convert from System.String.
   at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)
   at MS.Internal.Data.ObjectTargetConverter.ConvertBack(Object o, Type type, Object parameter, CultureInfo culture)
   at System.Windows.Data.BindingExpression.ConvertBackHelper(IValueConverter converter, Object value, Type sourceType, Object parameter, CultureInfo culture)'

I'm not sure how to go about creating a converter to convert a property value into the custom type.  Would you be able to help?  I've attached a sample project.


Thanks!

Alan


Attachment: CustomEditorWithNestedProperty_55852cae.zip

2 Replies

SN Sudharsan Narayanan Syncfusion Team October 5, 2021 03:58 AM UTC

Hi Alan,

Thanks for contacting Syncfusion support,

We have checked the reported issue that “Nested Property value changes occur error” from our end.
Currently, we are analyzing with our internal team for your reported issue. We will validate and update you the details on or before 6th October 2021.

Regards,

Sudharsan


SN Sudharsan Narayanan Syncfusion Team October 7, 2021 03:50 AM UTC

Hi Alan,

Thanks for the patience,

We have checked the reported issue that ”Convert a built-in type to custom type” from our end. Since the editor for the property "Level" is textbox editor and it converts everything, type to string, and two-way binding is done for the text editor value, it updates the string value to the class type. String value cannot be converted to class type, exception occurs. So, you can set property as Read-only or you can write Custom Editor to achieve his case.

Regards,
 
Sudharsan

Loader.
Up arrow icon