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

Auto Binding to object with nullable enums

6 Answers 223 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Oscar Ågren
Top achievements
Rank 1
Oscar Ågren asked on 08 Aug 2012, 09:19 AM
Hi,

I cant bind to an object with nullable enums using auto generated properties.
I get a silent error for every nullable enum property
System.Windows.Data Error: 1 : Cannot create default converter to perform 'two-way' conversions between types 'System.Nullable`1[Data.EF5.Enumerations.Unit]' and 'System.String'. Consider using Converter property of Binding. BindingExpression:Path=Unit1; DataItem='Mb' (HashCode=13923471); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')


Part of the enum looks like this (localized)

[TypeConverter(typeof(EnumToLocalizedName))]
   public enum Unit:int
   {
       [Display(Description = " ", ResourceType = typeof(Resources.Resource))]
       Unit0,
       [Display(Description = "°C", ResourceType = typeof(Resources.Resource))]
       Unit1
   ....
}

Non-nullable enums shows up in a combobox. How can I show my nullable enums the same way, without losing localization?

Thanks

6 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 13 Aug 2012, 11:17 AM
Hi,

Currently nullable enums are not supported by RadPropertyGrid in scenarios with auto-generated fields. We will do our best to add this feature in some of our future internal builds. I will write to you, in order to notify you as soon as the mentioned version is available. 

All the best,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Oscar Ågren
Top achievements
Rank 1
answered on 13 Aug 2012, 12:42 PM
Okey, thanks for clarifying. I was able to work around the nullable requirement. 

Still one problem remaining. How can I localize the enum names for the combobox? My typeconverter attribute is ignored. What attributes does the PropertyGrid require? Thanks
0
Ivan Ivanov
Telerik team
answered on 16 Aug 2012, 12:57 PM
Hi,

 We will need some more time, in order to check this. I will contact you tomorrow, in order to notify you of the results of our research. Please, excuse me for this delay.

Regards,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Ivan Ivanov
Telerik team
answered on 20 Aug 2012, 11:11 AM
Hi,

We have tested this scenario on our side and it appears that currently there is no easy workaround for this scenario. Would it be possible for you to use a non-nullable enum property and add a value that would mimic the null value, in the enum definition? The internal build that introduces support for Nullable enums will be released later today/tomorrow, but unfortunately the TypeConverter is not yet working properly with it.

All the best,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Oscar Ågren
Top achievements
Rank 1
answered on 20 Aug 2012, 10:56 PM
I have removed all nullable enums, it wasn't that big a loss, all I want now is to get localization for my non nullable enums. What would be the practiced pattern? Thanks
0
Ivan Ivanov
Telerik team
answered on 24 Aug 2012, 01:38 PM
Hi,

It seems that the EnumDataSource that we internally use in RadPropertyGrid fails to invoke the TypeConverter properly. We will need some more time to investigate this. I will contact you as soon as we have any updates.

All the best,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
PropertyGrid
Asked by
Oscar Ågren
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Oscar Ågren
Top achievements
Rank 1
Share this question
or