2

I have a dll that has a class called Series. This class has a field which is an enumeration of DataTypes. I am binding the datagrid to a list of objects of this class, and I am able to display the enumeration values in a combobox fashion However, the values' names don't make a lot of sense. For example, I want to display 'prc' as 'price' and still represent the correct object value.

this is what I currently do

            this.seriesDataTypeColumn.Items.AddRange(new object[] {
        MuDBLayer.DataType.mv,
        MuDBLayer.DataType.vol,
        MuDBLayer.DataType.num,
        MuDBLayer.DataType.prc,
        MuDBLayer.DataType.Composite});

mv, vol, num and prc are displayed in the datagridcomboboxes. I wanna display money value, volume, number, and price instead any ideas?

mustafabar
  • 2,317
  • 6
  • 31
  • 47
  • possible duplicate of [How do I have an enum bound combobox with custom string formatting for enum values?](http://stackoverflow.com/questions/796607/how-do-i-have-an-enum-bound-combobox-with-custom-string-formatting-for-enum-valu) – nawfal Jun 08 '13 at 23:37

2 Answers2

2

Description attribute cannot be localized. Do take a look at this reply.

Can my enums have friendly names?

Community
  • 1
  • 1
Trainee4Life
  • 2,203
  • 2
  • 22
  • 38
1

Take a look at https://msmvps.com/blogs/deborahk/archive/2009/07/10/enum-binding-to-the-description-attribute.aspx or http://blogs.freshlogicstudios.com/Posts/View.aspx?Id=388f7d39-0b90-43bc-b03a-c1f605dfb499. You can add a Description attribute to your enums to display a more friendly value.

You might also find some more information in this related question How to bind a custom Enum description to a DataGrid.

Community
  • 1
  • 1
mattruma
  • 16,589
  • 32
  • 107
  • 171
  • The description attribute approach works, but it shows the friendly values only upon drop down, but after selection it still shows the original ones. – mustafabar Sep 12 '09 at 13:49
  • Hmmm ... I usually load my enums into a NameValue class, and the binding displays correctly. – mattruma Sep 12 '09 at 15:00