enum

F

frivard

I have a Enum named "Status" with elements like

public enum Status : int
{
[Description("Treatment")] T = 82,
[Description("Complete")] C = 67,
}

I want to display de content of this Enum in a combobox.
In my combobox i want the [Description] attribute to be
displayed.

For example: I want "Treatment" as DisplayMember and "T"
as valueMember.

How can i do that ?
Thanks
 
N

Nicholas Paldino [.NET/C# MVP]

frivard,

I would enumerate through the values in your enumeration, getting the
description for each value. When you do this, I would create a data table
with two columns, one with a string value and one with a number. In the
string column, you will get the value from reflection for the description.
In the integer column, you will place the value of the enumeration itself.

Then, you can just bind to this dataset, and set the display member and
value member appropriately.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top