Connecting Tech Pros Worldwide Help | Site Map

dynamic enum creation

Steve Teeples
Guest
 
Posts: n/a
#1: Jul 21 '06
Given this definition of an enum:

enum MyEnum {
[Description("This is a descripiton of D1")]
d1=1,
[Description("This is a description of D2")]
d2=2
}

Is there a way to dynamically create this same enum at runtime? I want to
read variable data from a file, but this data into an enum to allow the user
to make a choice from a CheckedListBox. I am able to do this from a
predefined enum definition but want to be able to do it with variable data
read from files. As the mouse moves over the enumeration the "Description"
is shown to the user.

Is there some example somewhere of how this can be done?

--
-----------
Thanks,
Steve
Mythran
Guest
 
Posts: n/a
#2: Jul 21 '06

re: dynamic enum creation



"Steve Teeples" <SteveT@newsgroups.nospamwrote in message
news:A3D9A748-25BC-4AA1-9671-DBF370F4A689@microsoft.com...
Quote:
Given this definition of an enum:
>
enum MyEnum {
[Description("This is a descripiton of D1")]
d1=1,
[Description("This is a description of D2")]
d2=2
}
>
Is there a way to dynamically create this same enum at runtime? I want to
read variable data from a file, but this data into an enum to allow the
user
to make a choice from a CheckedListBox. I am able to do this from a
predefined enum definition but want to be able to do it with variable data
read from files. As the mouse moves over the enumeration the
"Description"
is shown to the user.
>
Is there some example somewhere of how this can be done?
>
--
-----------
Thanks,
Steve
I think what you are looking for in this context is not an enum
(programmatic name) but instead a list of dynamic values read from a
database (text file, spreadsheet, dbms, etc.). What you could do to get
this to work would be to load your data into a DataTable and then bind this
DataTable to the CheckedListBox. I'm not sure without testing, but I
believe this to be an easier route than dynamically creating an enum.

HTH,
Mythran


Michael Bray
Guest
 
Posts: n/a
#3: Jul 21 '06

re: dynamic enum creation


=?Utf-8?B?U3RldmUgVGVlcGxlcw==?= <SteveT@newsgroups.nospamwrote in
news:A3D9A748-25BC-4AA1-9671-DBF370F4A689@microsoft.com:
Quote:
Given this definition of an enum:
>
enum MyEnum {
[Description("This is a descripiton of D1")]
d1=1,
[Description("This is a description of D2")]
d2=2
}
>
Is there a way to dynamically create this same enum at runtime? I
want to read variable data from a file, but this data into an enum to
allow the user to make a choice from a CheckedListBox. I am able to
do this from a predefined enum definition but want to be able to do it
with variable data read from files. As the mouse moves over the
enumeration the "Description" is shown to the user.
>
Is there some example somewhere of how this can be done?

Are you specifically tied to dynamically creating an enum? Because you
don't have to add enum's to a CheckedListBox - you can add any object that
overrides ToString and it will display whatever the output of ToString is.

So instead of going to the pain of dynamically creating an enum, just
create a class that overrides ToString and create one for each value you
read from the database.

It doesn't answer your question, but it seems to address the issue you are
trying to solve.

-mdb
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#4: Jul 21 '06

re: dynamic enum creation


Hi ,

Frankly there is no use at all for a "dynamic enum" , an enum is just a nice
way to give names to values, it's intended only at easying the written of
code and is interpreted at compile time.

What you are after is a collection


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Steve Teeples" <SteveT@newsgroups.nospamwrote in message
news:A3D9A748-25BC-4AA1-9671-DBF370F4A689@microsoft.com...
Quote:
Given this definition of an enum:
>
enum MyEnum {
[Description("This is a descripiton of D1")]
d1=1,
[Description("This is a description of D2")]
d2=2
}
>
Is there a way to dynamically create this same enum at runtime? I want to
read variable data from a file, but this data into an enum to allow the
user
to make a choice from a CheckedListBox. I am able to do this from a
predefined enum definition but want to be able to do it with variable data
read from files. As the mouse moves over the enumeration the
"Description"
is shown to the user.
>
Is there some example somewhere of how this can be done?
>
--
-----------
Thanks,
Steve

Brennon WIlliams
Guest
 
Posts: n/a
#5: Aug 3 '06

re: dynamic enum creation


No use for a Dynamic enum?

How would you suggest creating a list to be displayed in a property grid, built with values only exposed at runtime?

A collection will not give you a list of values, but a new property grid view with each collection item as an object.

Closed Thread