Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-05-02
4
Medium Priority
?
390 Views
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

Thanks

Syed
0
Comment
Question by:snomi
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 13911535
 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
 

Author Comment

by:snomi
ID: 13937311
It seems to be a good solutions.

I will definitely try this today.

Thanks a lot

Syed
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

580 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