Enum Binding
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.Button2 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
Me.Button1.Location = New System.Drawing.Point(104, 24)
Me.Button1.Size = New System.Drawing.Size(184, 24)
Me.Button1.Text = "Bind to Enum"
'
Me.ListBox1.Location = New System.Drawing.Point(104, 112)
Me.ListBox1.Size = New System.Drawing.Size(184, 82)
'
Me.Button2.Location = New System.Drawing.Point(104, 64)
Me.Button2.Size = New System.Drawing.Size(184, 24)
Me.Button2.Text = "Display Value of Selected"
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(392, 246)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.ListBox1, Me.Button1})
Me.ResumeLayout(False)
End Sub
Public Enum Test
A = 1
B = 2
C = 3
End Enum
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.DataSource = System.Enum.GetNames(GetType(Test))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strNames As Array = System.Enum.GetValues(GetType(Test))
Dim strValue As String = strNames(ListBox1.SelectedIndex)
MessageBox.Show(strValue)
End Sub
End Class
Related examples in the same category