【问题标题】:How do you change an enum value to a more readable string that is bound to a UltraGrid?如何将枚举值更改为绑定到 UltraGrid 的更易读的字符串?
【发布时间】:2014-11-18 15:22:55
【问题描述】:

我有一个 Infragistics UltraGrid,其中包含各种数据类型的绑定列表。其中之一是具有非人类可读值的枚举。我想将显示更改为更具可读性。

在代码库中,人们一直在隐藏枚举列并添加具有所需值的字符串列。这对我来说似乎不正确。有没有办法改变显示的枚举值,使其更具可读性?

示例。不可读:
一些不可读的枚举值
Some_Unreadable_Enum_Value

可读性:
一些可读的文本

更新:
我知道使用描述属性

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

正如这里提到的See Thomas Levesque answer。我只是不知道如何将此描述属性绑定到已经绑定到枚举的 UltraGrid。

【问题讨论】:

标签: c# .net enums infragistics ultrawingrid


【解决方案1】:

我只是创建一个返回描述的属性并绑定到它

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;

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多