473,397 Members | 2,084 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,397 software developers and data experts.

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
Jul 21 '06 #1
4 20092

"Steve Teeples" <St****@newsgroups.nospamwrote in message
news:A3**********************************@microsof t.com...
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
Jul 21 '06 #2
=?Utf-8?B?U3RldmUgVGVlcGxlcw==?= <St****@newsgroups.nospamwrote in
news:A3**********************************@microsof t.com:
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
Jul 21 '06 #3
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" <St****@newsgroups.nospamwrote in message
news:A3**********************************@microsof t.com...
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

Jul 21 '06 #4
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.

Aug 2 '06 #5

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

Similar topics

5
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK'...
8
by: Eyeawanda Pondicherry | last post by:
I have put some code together that creates an enum dynamically from some database values. The enum can be read perfectly by an application that references the dynamically generated dll. If I...
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
15
by: rwf_20 | last post by:
I just wanted to throw this up here in case anyone smarter than me has a suggestion/workaround: Problem: I have a classic producer/consumer system which accepts 'commands' from a socket and...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
13
by: toton | last post by:
Hi, I have some enum (enumeration ) defined in some namespace, not inside class. How to use the enum constant's in some other namespace without using the whole namespace. To say in little...
10
by: Charlie | last post by:
I tried to post this before and I apologize if I am repeating myself, but I do not see the post anywhere. But anyway, I have a file, data.c, where I define all of my global variables. I then...
1
by: pete m | last post by:
I would like to support stdio functions for an extremely primitive type system, as shown in the attached sample program, using dynamic creation of a va_list. I've tested it on successfully a...
1
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.