473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

enum

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
Nov 15 '05 #1
3 2413
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"frivard" <de*******@sogescom.net> wrote in message
news:07****************************@phx.gbl...
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

Nov 15 '05 #2
Frivard,
You will need to reflection to load the values into the combobox.

The following articles should get you started.

http://msdn.microsoft.com/library/de...natruntime.asp

http://msdn.microsoft.com/library/de...attributes.asp

Hope this helps
Jay

"frivard" <de*******@sogescom.net> wrote in message
news:07****************************@phx.gbl...
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

Nov 15 '05 #3
Check out this excelent article on using the static members of the Enum
class instead of doing all the reflection work yourself.
http://msdn.microsoft.com/msdnmag/issues/01/10/net/
--Ken

"frivard" <de*******@sogescom.net> wrote in message
news:07****************************@phx.gbl...
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

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
18
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
2
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
10
by: Randy | last post by:
Hi, Can anyone point me to a complete, compilable example of Besser's ENUM++ mechanism? I downloaded it from CUJ and gave it a try but got errors just trying to compile the header enum.h. ...
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.