私はこのことができますどのくらいわからないんだけど、私はこのようになります列挙型の拡張メソッドを使用します。
/// <summary>
/// Returns the value of the description attribute attached to an enum value.
/// </summary>
/// <param name="en"></param>
/// <returns>The text from the System.ComponentModel.DescriptionAttribute associated with the enumeration value.</returns>
/// <remarks>
/// To use this, create an enum and mark its members with a [Description("My Descr")] attribute.
/// Then when you call this extension method, you will receive "My Descr".
/// </remarks>
/// <example><code>
/// enum MyEnum {
/// [Description("Some Descriptive Text")]
/// EnumVal1,
///
/// [Description("Some More Descriptive Text")]
/// EnumVal2
/// }
///
/// static void Main(string[] args) {
/// Console.PrintLine(MyEnum.EnumVal1.GetDescription());
/// }
/// </code>
///
/// This will result in the output "Some Descriptive Text".
/// </example>
public static string GetDescription(this Enum en)
{
var type = en.GetType();
var memInfo = type.GetMember(en.ToString());
if (memInfo != null && memInfo.Length > 0)
{
var attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attrs != null && attrs.Length > 0)
return ((DescriptionAttribute)attrs[0]).Description;
}
return en.ToString();
}
あなたが戻るために、あなたのオブジェクトのカスタムプロパティのゲッターを使用することができます名前:
public class TestResult
{
public string TestDescription { get; set; }
public ExpectationResult RequiredExpectationResult { get; set; }
public ExpectationResult NonRequiredExpectationResult { get; set; }
/* *** added these new property getters *** */
public string RequiredExpectationResultDescr { get { return this.RequiredExpectationResult.GetDescription(); } }
public string NonRequiredExpectationResultDescr { get { return this.NonRequiredExpectationResult.GetDescription(); } }
}
次に "RequiredExpectationResultDescr" と "NonRequiredExpectationResultDescr" プロパティに、あなたのグリッドをバインドします。少し過剰に複雑かもしれません
が、その私は2つの他の回答に基づいて:)
ありがとうMarc! EnumHelper(rally25rsの答えの最初の部分と同様)と組み合わせることで、このエレガントなソリューションは、DataGridViewで美しく機能します。残念ながら、DevExpress.XtraGrid.GridControlは** TypeConverter属性を検出しません。一口。しかし、あなたの答えははっきりと正しいです。 – TrueWill
...あなたは正しい方向に私を指差した。私は、Developer Expressがこれをサポートする予定がなく、この回避策を提供していることが判明しました:http://www.devexpress.com/Support/Center/p/CS2436.aspx – TrueWill