Link to home
Start Free TrialLog in
Avatar of nepaluz
nepaluzFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

<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

Open in new window


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

        Dim iSa As New DataGridViewComboBoxColumn
        With iSA
            .DataSource = System.Enum.GetValues(GetType(WorkingDaysOfWeek.iWeekDay))
            .Name = "Days"
            .FlatStyle = FlatStyle.Flat
        End With

Open in new window


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.
ASKER CERTIFIED SOLUTION
Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nepaluz

ASKER

jtoutou - thanks for the response.

Your code (should) work, however, it does not take into consideration of the "duo" purpose of my code request and question.

1. In the first place, the class serialize to XML (your suggested solution does not cater for that).

2. The second purpose is to have a working comboboxcell. My code above DOES produce a combocell bound to the enumeration (again as illustrated), however, there seems to be an issue with the displyed value (after selecting from the combo), which was my request for help (NOT INDEPENDENT OF THE SERIALIZATION!).
I may be missing something from your code, but may I request a more complete code sample with serialization included?

Avatar of nepaluz

ASKER

It should have been obvious (having tested the code) that this was the solution, and it indeed is the solution.

jtoutou - could you be a bit more verbose next time PSE!???