Combobox getting data from a localizable enum / enum file  
Author Message
Master Hugo





PostPosted: Visual C# General, Combobox getting data from a localizable enum / enum file Top

Hey,

the problem is,how to turn an enum localizable and to fill it in a combobox

I saw this example :

http://www.hide-link.com/ ;forumid=164596&exp=0&select=1064318#xx1064318xx

but in that example the resource file contents, has names like "attribute.name", i can't insert a string in the resource file with a dot.

Thank you for help!

Hugo Araujo



Visual C#7  
 
 
Peter Ritchie





PostPosted: Visual C# General, Combobox getting data from a localizable enum / enum file Top

You can't localize enum names (those retreived from Enum.ToString()) and you can't localize Attribute values.

The only thing you can do is use a enum value to lookup text in the resources so the resource manager can load the appropriate text for the CurrentUICulture. You could use the enum name as the Name in your resources. For example, if you had the following enum:

enum Ordinal

{

Unknown = 0,

First = 1,

Second = 2,

}

And the following entries in your resources:

<data name="First" xml:space="preserve">

<value>1st</value>

</data>

<data name="Second" xml:space="preserve">

<value>2nd</value>

</data>

<data name="Third" xml:space="preserve">

<value>3rd</value>

</data>

You could get "1st" using:

String text = global::MyNamespace.Properties.Resources.ResourceManager.GetString(Ordinal.First.ToString());

Or:

String text = global::MyNamespace.Properties.Resources.ResourceManager.GetString("First");

Or, if you didn't want to couple the enum value name to something in the resources you could use a switch:

Ordinal ordinal = Ordinal.First;

switch (ordinal)

{

case Ordinal.First:

text = global::MyNamespace.Properties.Resources.ResourceManager.GetString("SomeName");

break;

case Ordinal.Second:

text = global::MyNamespace.Properties.Resources.ResourceManager.GetString("SomeOtherName");

break;

default:

text = global::MyNamespace.Properties.Resources.ResourceManager.GetString("UnknownMessage");

break;

}



 
 
Master Hugo





PostPosted: Visual C# General, Combobox getting data from a localizable enum / enum file Top

Thanks a lot!