0

I have an Infragistics UltraGrid with a bound list of various datatypes. One of these is an enum with non-human readable values. I would like to change the display to something more readable.

In the code base people have been hiding the enum column and adding a string column with the desired values. This doesn't seem right to me. Is there a way of changing the displayed enum values that would be more readable?

Example. Not Readable:
SomeUnreadableEnumValue
Some_Unreadable_Enum_Value

Readable:
Some Readable Text

Update:
I am aware of using Description attributes

public enum MyEnum
{
    [Description("Description for Foo")]
    Foo,
    [Description("Description for Bar")]
    Bar
}

as mentioned here See Thomas Levesque answer. I just can't figure out how to bind this description attribute to an UltraGrid that is already bound to an enum.

Community
  • 1
  • 1
Fuyu Persimmon
  • 483
  • 6
  • 13
  • http://stackoverflow.com/questions/11531739/linking-enum-value-with-localized-string-resource – Marton Nov 18 '14 at 15:32
  • @Marton I have already tried the Description attribute approach. This is actually the approach I want to take. The problem is how to get the grid to display this value when it is already bound to an enum. – Fuyu Persimmon Nov 18 '14 at 15:51
  • Not sure if you already looked at this link, http://stackoverflow.com/questions/773303/splitting-camelcase – Suni Nov 18 '14 at 15:54

1 Answers1

1

I just create a property that returns the description and bind to it

public override string UserTextOp
{
    get
    {
        Type enumType = typeof(enumTextCond);
        string name = Enum.GetName(enumType, cond1SelectedKeyEnum);
        if (name != null)
        {
            FieldInfo field = enumType.GetField(name);
            if (field != null)
            {
                DescriptionAttribute attr =
                        Attribute.GetCustomAttribute(field,
                            typeof(DescriptionAttribute)) as DescriptionAttribute;
                if (attr != null)
                    name = attr.Description;
            }
            return name;
        }
        return string.Empty;

    }
}
paparazzo
  • 44,497
  • 23
  • 105
  • 176