Enum Binding : ListBox « GUI « VB.Net






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

1.Toggling list box Selection Mode: select one or select more than oneToggling list box Selection Mode: select one or select more than one
2.Draw selected Item in ListBoxDraw selected Item in ListBox
3.Owner Draw ListBoxOwner Draw ListBox
4.Add Item to ListBoxAdd Item to ListBox
5.Add Item to a List Box by clicking a ButtonAdd Item to a List Box by clicking a Button
6.Get Selected Item from ListBoxGet Selected Item from ListBox
7.Add, remove and clear list box itemsAdd, remove and clear list box items
8.List Box and Spinner DemoList Box and Spinner Demo
9.Customize ListBox Font and Item HeightCustomize ListBox Font and Item Height
10.Drag and drop between two ListBoxDrag and drop between two ListBox
11.Set ListBox TopIndexSet ListBox TopIndex