views:

337

answers:

2

Hi. 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?

A: 

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 http://stackoverflow.com/questions/582105/how-to-bind-a-custom-enum-description-to-a-datagrid.

mattruma
The description attribute approach works, but it shows the friendly values only upon drop down, but after selection it still shows the original ones.
Mustafa A. Jabbar
Hmmm ... I usually load my enums into a NameValue class, and the binding displays correctly.
mattruma
+1  A: 

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

http://stackoverflow.com/questions/1415140/c-enums-can-my-enums-have-friendly-names/1415579#1415579

Trainee4Life