Having Enums is nice, having the in a combobox without writing a lot of manual code is even nicer.
Here is how its done:
On a Form add a combobox and a textbox (multiline).
Add code below:
Enum ePets
eA_Dog = 0
eA_Cat = 1
eA_Hamster = 7
eA_GoldFish = 33
End Enum
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Make it a list so user cannot changes text etc
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
' Load Enums to Combobox
ComboBox1.Items.AddRange([Enum].GetNames(GetType(ePets)))
ComboBox1.SelectedIndex = 0 ' Point to first item
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
' Get text from selected combo, parse it to a Enum instead
Dim a As ePets = [Enum].Parse(GetType(ePets), ComboBox1.Text)
Dim y As Integer = a
Dim txt As String = "ComboText: " + ComboBox1.Text + vbCrLf
txt += "ComboIndex: " + ComboBox1.SelectedIndex.ToString + vbCrLf
txt += "Enum + Value: " + a.ToString + ", " + Integer.Parse(a).ToString
TextBox1.Text = txt
' Convert y integer to Enum
Dim a1 As ePets = [Enum].Parse(GetType(ePets), y)
Debug.Print(a1.ToString)
End Sub
Enjoy.
Thursday, February 12, 2015
Subscribe to:
Posts (Atom)
MySQL to MariaDB
Here is a good description how to migrate to MariaDb MySQL to MariaDb Example of how to dump data from MySQL port=3307: mysqldump --user=ro...
-
When converting an VB2008 application to VB2010 I run into trouble regarding COM objects while compiling. you get errors like: Error 1...
-
In a module you have declared a Structure or Enum that you will use through out a project. Module Module1 Public Structure dummy ...
-
Apache2 crashes on Ubuntu Linux 22.04.5 after Zabbix was updated to 7.0.26 During a upgrade of my Ubuntu server there was a new package for ...