Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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

VB
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
Posted

1 solution

Do you have any events handled for the combo box or the binding source?

For example if you would have handled the Validating event for the combo and the Cancel is set to true then you wouldn't be able to get to the next control until you have a valid entry.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900