By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,558 Members | 1,673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,558 IT Pros & Developers. It's quick & easy.

Bind Enum to ComboBox in GridView

P: n/a
I am binding to a collection of Business Objects in a GridView (Windows App,
..NET 2.0).

In my Business Object I have a Property that is an ENUM.

I want a Drop down box in the Grid that is Bound to the property that is of
the type of the ENUM. I want the combo box filled in with the list of ENUM
values.

Does the GridView support this?
Brien King
br***@classic-soft.com
Feb 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

You can try something like this. You need to manually remove the
column from the gridview and add the column back in. You can see a
complete example here

http://www.vb-tips.com/default.aspx?...a-62c7a184f472

Here is the code. I did not set the column the datagridview combo is bound
to. It will show the display member but keep the value member as its value.
Dim lstEnum As New List(Of enumBindTo)
Dim arColor() As String
arColor = KnownColor.GetNames(GetType(KnownColor))

For x As Int16 = 0 To arColor.GetUpperBound(0)
Dim cls As New enumBindTo
With cls
.EnumValue = x
.StringValue = arColor(x)
End With
Next

Dim dgvEnum As New DataGridViewComboBoxColumn
With dgvEnum
.Width = 150
.DataSource = lstEnum
.ValueMember = "EnumValue"
.DisplayMember = "StringValue"
.HeaderText = "Color"
End With

DataGridView1.Columns.Add(dgvEnum)

The class I used

Public Class enumBindTo

Private mintEnumValue As Integer
Public Property EnumValue() As Integer
Get
Return mintEnumValue
End Get
Set(ByVal value As Integer)
mintEnumValue = value
End Set
End Property

Private mstrValue As String
Public Property StringValue() As String
Get
Return mstrValue
End Get
Set(ByVal value As String)
mstrValue = value
End Set
End Property

End Class

Ken
----------------

"Brien King" <br***@classic-soft.com> wrote in message
news:eZ**************@TK2MSFTNGP12.phx.gbl...
I am binding to a collection of Business Objects in a GridView (Windows
App, .NET 2.0).

In my Business Object I have a Property that is an ENUM.

I want a Drop down box in the Grid that is Bound to the property that is
of the type of the ENUM. I want the combo box filled in with the list of
ENUM values.

Does the GridView support this?
Brien King
br***@classic-soft.com

Feb 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.