Search code examples
c#.netenumsdropdownbox

Binding Drop down with localized value using enum in C#


Binding Drop down with localized value using enum in C#.

I have value for all the languages. So I do not need to fetch it from anywhere else. I can write all the value in different languages resx file. But I am not sure how it works.

I am using C# windows form. framework 3.5


Solution

  • I have used following code and it works fine for me

    using System.Globalization;
    using System.ComponentModel;
    using System.Threading;
    

    .......

    .......

    .......

    Thread.CurrentThread.CurrentUICulture = new CultureInfo(DDLLang.SelectedValue);
    ComponentResourceManager resource = new ComponentResourceManager(typeof(Default));
    resource.ApplyResources(LblName, "LblName");
    LblName.ID = "LblName";
    Response.Write(resource.GetString("strMsg",CultureInfo.CurrentUICulture)??resource.GetString("strMsg"));
    

    In above code LblName is a Label and StrMsg a simple string.

    In resource file I will write like this:

    Name Value


    Lbl.Name labelname................

    StrMsg anycustom msg............