Enum

danasegarane

Active member
Joined
Jun 14, 2006
Messages
41
Programming Experience
Beginner
Dear All,
How can Build a Enum during run time.
Now i have like this
VB.NET:
   Public Enum Test
        val1
        val1
      End Enun

Now the problem is that the members cannot be declared during design time.It will be defined during run time only.How can I build during run time

Thks in advance
Dana
 
Dana,

No need to prefix your subject line with [2005], please update your Primary Development Platform in the User CP area. I removed the prefix from your subject line.

Thank you.
 
Would that make any sense? If the enum/member don't exist at design time, how can you write code that uses that enum/member?
 
Dear John,
I am using the code to display some file information.
VB.NET:
Imports System.ComponentModel
Imports System.IO
Public Class FilePropertyGrid
    Public sInputFileName As String
    Private sFileName As String
    Private lFilesize As Long
    Private sFiletype As String
    Private sFileModifiedDate As Date
    Private sT As TextEnum
    Public sTest As New Hashtable
    Public xArray() As String
    ' Public sText

    <Category("FileDescription"), DefaultValue(""), Description("FileName")> _
    Public Property FileName() As String
        Get
            If File.Exists(sInputFileName) = True Then
                sFileName = New FileInfo(sInputFileName).Name
            End If
            Return sFileName
        End Get
        Set(ByVal value As String)
            sFileName = value
        End Set
    End Property
    <Category("FileDescription"), DefaultValue(""), Description("File Size")> _
    Public Property Size() As Long
        Get
            If File.Exists(sInputFileName) = True Then
                lFilesize = New FileInfo(sInputFileName).Length
            End If
            Return lFilesize
        End Get
        Set(ByVal value As Long)
            lFilesize = value
        End Set
    End Property
    Public Property sText() As TextEnum
        Get
            Return sT
        End Get
        Set(ByVal value As TextEnum)
            sT = TextEnum.Value1
        End Set
    End Property
   [COLOR=Orange] Public Enum TextEnum
        Value1
        Value2
        Value3
    End Enum[/COLOR]
Now what i want to do is to populate the members of the TextEnum from the return rows from the query.
 
Last edited:
What rows? what query?
 
I am retriving the values from the sql table .The returned rows may contain values depends upon the query.This may varry like

Val1
val2
Val3

or
Val1
Val2
Val3
Val4
Val5
 
Define the Enum members at design time, use Enum.Parse to get enum value from string.
 
You can't, because you can't use a type in code that isn't defined.

It looks as you are trying to provide a selection list for propertygrid, have a read at Using PropertyGrid Part-I the section 'Adding custom dropdown list' seems to do what you want.
 
Back
Top