How to Assign an Enum to a combo box in

Posted on 2005-05-02
Last Modified: 2006-11-18
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


Question by:snomi
    LVL 96

    Accepted Solution

     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


    Author Comment

    It seems to be a good solutions.

    I will definitely try this today.

    Thanks a lot


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now