How to Assign an Enum to a combo box in vb.net

I have an ENUM

Public Enum NsiSearchOperatorEnum
  Contains = 1          
   DoesNotContain = 2    
   Isexactly = 3          
   IsEmpty = 4  
End Enum


How do i assign this enum to my combo box. so that its
                displayItem may have Contains, or does not contain in the list
and value field (inner code ) have 1, 2 etc

how is that possible

plz tell me with code how's that possible

Thanks

Syed
snomiAsked:
Who is Participating?
 
Bob LearnedCommented:
 Public Enum NsiSearchOperatorEnum
    Contains = 1
    DoesNotContain = 2
    Isexactly = 3
    IsEmpty = 4
  End Enum


  Public Class Operator

    Public Name As String
    Public Type As NsiSearchOperatorEnum

    Public Sub New(ByVal newName As String, ByVal newType As NsiSearchOperatorEnum)

      Me.Name = newName
      Me.Type = newType

    End Sub


    Public Overrides Function ToString() As String

      Return Me.Name

    End Function

  End Class


  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.ComboBox1.Items.Add(New Operator("Contains", NsiSearchOperatorEnum.Contains))
    Me.ComboBox1.Items.Add(New Operator("Does Not Contain", NsiSearchOperatorEnum.DoesNotContain))
    Me.ComboBox1.Items.Add(New Operator("Is Empty", NsiSearchOperatorEnum.IsEmpty))
    Me.ComboBox1.Items.Add(New Operator("Is Exactly", NsiSearchOperatorEnum.Isexactly))

  End Sub


  Private Sub ComboBox1_SelectedItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged

    MessageBox.Show(DirectCast(Me.ComboBox1.SelectedItem, Operator).Type.ToString)

  End Sub

Bob
0
 
snomiAuthor Commented:
It seems to be a good solutions.

I will definitely try this today.

Thanks a lot

Syed
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.