I have a ComboBox that is data bound to a property of an object. The ComboBox contains a list of Enum values and descriptions which I have generated as follows:
Public Class Enumeration
#Region "Enumeration handling mothods"
Public Shared Function GetList(ByVal Enumerator As Type) As Enumeration.List
Dim items As New Enumeration.List
Dim values() As Integer = System.Enum.GetValues(Enumerator)
For Each enumItemId As Integer In values
Dim enumItem As New Item(enumItemId, System.Enum.GetName(Enumerator, enumItemId))
items.Add(enumItem)
Next
Return items
End Function
Public Class Item
Private _iId As Integer
Public ReadOnly Property Id() As Integer
Get
Return _iId
End Get
End Property
Private _sDescription As String
Public ReadOnly Property Description() As String
Get
Return _sDescription
End Get
End Property
Public Sub New(ByVal EnumId As Integer, ByVal EnumDescription As String)
_iId = EnumId
_sDescription = EnumDescription
End Sub
End Class
Public Class List
Inherits List(Of Enumeration.Item)
Default Public Shadows Property Item(ByVal index As Integer) As Item
Get
Return MyBase.Item(index)
End Get
Set(ByVal value As Item)
MyBase.Item(index) = value
End Set
End Property
Public Sub New()
MyBase.New()
End Sub
Public Shadows Sub Add(ByVal EnumItem As Item)
MyBase.Add(EnumItem)
End Sub
End Class
#End Region
End Class
and my Enum is defined as follows
Public Enum Statuses
Unspecified = 0
Active = 1
OutOfService = 10
Sold = 50
Scrapped = 99
End Enum
The
SelectedValue
property of the ComboBox binding is sent to the myOject.Status property
In the Form Load event
myBindingSource.DataSource = _oMyObject
statusComboBox.DataSource = Enumeration.GetList(GetType(MyObject.Statuses))
I can select any of the statues, but it will not let me leave the ComboBox. If I remove the binding then the comboBox operates as expected, except then the object property value is not updated.
Any help greatly appreciated.
Thanks