Connecting Tech Pros Worldwide Help | Site Map

dynamic enum creation

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 21st, 2006, 04:25 PM
Steve Teeples
Guest
 
Posts: n/a
Default dynamic enum creation

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

  #2  
Old July 21st, 2006, 04:45 PM
Mythran
Guest
 
Posts: n/a
Default 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


  #3  
Old July 21st, 2006, 04:45 PM
Michael Bray
Guest
 
Posts: n/a
Default 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
  #4  
Old July 21st, 2006, 04:55 PM
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
Default 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

  #5  
Old August 2nd, 2006, 11:25 PM
Brennon WIlliams
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.