473,769 Members | 3,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bind Enum to ComboBox in GridView

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
1 9783
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.GetN ames(GetType(Kn ownColor))

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

Dim dgvEnum As New DataGridViewCom boBoxColumn
With dgvEnum
.Width = 150
.DataSource = lstEnum
.ValueMember = "EnumValue"
.DisplayMember = "StringValu e"
.HeaderText = "Color"
End With

DataGridView1.C olumns.Add(dgvE num)

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***@classi c-soft.com> wrote in message
news:eZ******** ******@TK2MSFTN GP12.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2151
by: COHENMARVIN | last post by:
I'm leafing through a big book on asp.net, and I don't see any way to the following: 1. bind values and text to a dropdown 2. Also make the first line of the dropdown say something different. For instance, if I'm working with a table of hotels, I might want a 'select' control as follows <select id="mylistbox" runat="server"> <option value="*">Add New Hotel</option> <option value="1">The Hilton</option> <option value="2">The...
5
34944
by: Steven Baggs | last post by:
Hi!, I have defined a List<T> like this List<Container> Container class holds my Item object and it's state as a Enum. Container.Item Container.State I would like to bind it to GridView.
3
3322
by: wallermj | last post by:
I am an inexperienced asp.net user starting my first app in asp.net. I need to have a combobox field in my gridview whose data is filtered by a field in that row. More specifically, I am to display all the invoice numbers (there can be many) tied to the container number displayed on the row. Each row has a different container number so in each row the combobox will need to display different information. I have found code to help me...
9
13906
by: Jakob Lithner | last post by:
1) I have a DataGridView with edit capability. But in some columns I want to limit the input with a DropDownList. There is no inbuilt column for DropDownLists so I intended to add one myself. I thought the TemplateField would be a good candidate so I added a DropDownList in the EditItemTemplate and a Literal in the ItemTemplate, but then I was kind of lost .... It would be convenient to use the DataGridView for all other fields but maybe...
0
1724
by: teclioness | last post by:
Hi, I am using gridview for the user to update rows. In a row, there sre two columns, which need to be updated. When the gridview is to be shown, the row should show the values from database. When user clicks on edit link, should display the windows loginId in one column and in second column, show the current datetime. When user clicks on update link, should save these two column values to database as well as other updated field values....
6
29207
by: Fao, Sean | last post by:
Is it possible to bind a GridView to a generic Dictionary object? When I try it in my ASP.NET application, it throws an exception acknowledging that the specified field or property does not exist. The problem, I think, is that the GridView cannot see "inside" of the generic Dictionary. I suspect this because setting the AutoGenerateColumns property of the GridView causes the GridView to display only the Key property, which is, of...
7
9837
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
3
3092
by: Steve Kershaw | last post by:
Hi, I need a way to bind a DirectoryInfo array to a GridView without any errors. The code I'm using to create the DirectoryInfo array is: // Define the current directory DirectoryInfo dir = new DirectoryInfo("C:\\Temp\\");
0
2591
by: pavanip | last post by:
Hi, I am facing problem with combobox in gridview.I have used combobox in gridview and i am binding data to gridview combobox from database. If i click 2 times on combobox then it is showing the items and first item looks like blank. Can anybody help me to resolve this problem how to display items in gridview combobox without double click and it will show first item by default without selection.The application is windows application. ...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.