Question : VB.net Binding DataGridViewComboBoxCell to Enumeration

I have the following code to define and set up my enumeration which I want to bind to a datagridviewcomboboxcell

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
<System.SerializableAttribute(), _
 System.Xml.Serialization.XmlTypeAttribute([Namespace]:="")> _
Partial Public Class WorkingDaysOfWeek
    Private iDay As iWeekDay
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)> _
    Public Property HELDINACCT() As iWeekDay
        Get
            Return Me.iDay
        End Get
        Set(ByVal value As iWeekDay)
            Me.iDay = value
        End Set
    End Property

    <System.SerializableAttribute(), _
 System.Xml.Serialization.XmlTypeAttribute([Namespace]:="")> _
    Enum iWeekDay
        Monday
        Tuesday
        Wednesday
        Thursday
        Friday
    End Enum

End Class


I then use this routine to bind the enumeration to the datagridviewcomboboxcolumn

1:
2:
3:
4:
5:
6:
        Dim iSa As New DataGridViewComboBoxColumn
        With iSA
            .DataSource = System.Enum.GetValues(GetType(WorkingDaysOfWeek.iWeekDay))
            .Name = "Days"
            .FlatStyle = FlatStyle.Flat
        End With


My question is:

I am using VB 2010 Express edition and whenever I select a value from any cell in the combo column, the DISPLAYED value always returns to Monday (notwithstanding that I may have chosen another day).

Is this because of the way I have defined my class and enumeration, or is there some setting I have to make in the datagridview itself?

PS. I use the class above as part of a bigger class that serializes to XML. Incidentally, all enumerations in that class (sisters of the above) behave in the same way when bound to a DataGridviewComboboxCell / Column.

Answer : VB.net Binding DataGridViewComboBoxCell to Enumeration

try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Public Shared Function BindEnumeration(ByVal _enum As Type) As ArrayList
        'get the names from the enumeration
        Dim enumNames() As String = System.Enum.GetNames(_enum)
        'get the values from the enumeration
        Dim enumValues() As Integer = System.Enum.GetValues(_enum)
        'turn it into a hash table
        Dim aList As New ArrayList()
        For i As Integer = 0 To enumNames.Length - 1
            aList.Insert(enumValues(i), enumNames(i))
        Next
        Return aList
    End Function
    Enum iWeekDay
        Monday
        Tuesday
        Wednesday
        Thursday
        Friday
    End Enum
DatsGridViewComboBox.DataSource = BindEnumeration(GetType(iWeekDay))
Random Solutions  
 
programming4us programming4us