S
Sampson
I have a question about enumeration and how to populate them during
runtime.
I am using vb.net but will happily take any advice in c# as well.
Here is an example to help illustrate what I am after.
Create a class named “clsMyItems” and in that class place an enum.
Public Enum Items
Item1 = 0
Item2 = 1
Item3 = 2
End Enum
Now from another class call the Items enum.
Dim MyItems as new clsMyItems
MyItems.Items.
After typing the last dot in “MyItems.Items.” the intellisense will show
a nice drop down list of all the enumerated items in Items. This is
exactly what I am looking for.
Now for the problem…
I don’t know ahead of time what items or how many of them will be listed
in the Items enum. This is just a simplified example of what will
eventually go into a custom control I am working on. If I can get past
this issue it will make the control insanely easy to use.
Is there a way to populate the Items enum at runtime or an equivalent
method that will give me the drop down list I so desperately need.
If it makes a difference, the control inherits from
System.ComponentModel.Component
I could do it as System.Windows.Forms.UserControl but I would prefer to
do it as a component since it will never be seen on any form.
Its primary use is for windows forms but it will be used on web forms
I’m sure.
runtime.
I am using vb.net but will happily take any advice in c# as well.
Here is an example to help illustrate what I am after.
Create a class named “clsMyItems” and in that class place an enum.
Public Enum Items
Item1 = 0
Item2 = 1
Item3 = 2
End Enum
Now from another class call the Items enum.
Dim MyItems as new clsMyItems
MyItems.Items.
After typing the last dot in “MyItems.Items.” the intellisense will show
a nice drop down list of all the enumerated items in Items. This is
exactly what I am looking for.
Now for the problem…
I don’t know ahead of time what items or how many of them will be listed
in the Items enum. This is just a simplified example of what will
eventually go into a custom control I am working on. If I can get past
this issue it will make the control insanely easy to use.
Is there a way to populate the Items enum at runtime or an equivalent
method that will give me the drop down list I so desperately need.
If it makes a difference, the control inherits from
System.ComponentModel.Component
I could do it as System.Windows.Forms.UserControl but I would prefer to
do it as a component since it will never be seen on any form.
Its primary use is for windows forms but it will be used on web forms
I’m sure.