473,728 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enum and combobox

does anybody know how to use all values of an enumeration in a combobox?

i have an enum type defined like
public enum EnumTest
{
val1 = 1,
val2 = 2,
val4 = 4,
}

i would like to bind this to a combobox so that i can use 'val1' als the
displaymember of the combobox and the int as the valuemember.

any ideas?

thanks,
Dries
Dec 19 '05 #1
3 9821
Franky

You can use Enum.GetNames to return the constants used. Also, use
Enum.GetValues to return the values.

Use a loop to iterate over and assign to your combobox.

Mark

"Franky" <dr***@bestopia .be> wrote in message
news:11******** *******@seven.k ulnet.kuleuven. ac.be...
does anybody know how to use all values of an enumeration in a combobox?

i have an enum type defined like
public enum EnumTest
{
val1 = 1,
val2 = 2,
val4 = 4,
}

i would like to bind this to a combobox so that i can use 'val1' als the
displaymember of the combobox and the int as the valuemember.

any ideas?

thanks,
Dries

Dec 19 '05 #2
> Use a loop to iterate over and assign to your > combobox.

I think it can be done without the loop.
Look it up in the docs.
Roger
Dec 19 '05 #3
Yes, as long as it supports the IList interface, you can just databind the
array that is returned to the combobox.

Mark

"Roger" <ro***@pcsreven uecontrol.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Use a loop to iterate over and assign to your > combobox.


I think it can be done without the loop.
Look it up in the docs.
Roger

Dec 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4372
by: Cody Manix | last post by:
is there a way to explicitly assign a name to an enum member? what about internationalisation? one must be able to change the text. i'd like to implemtent it this way: enum Color = { Red="Rot", Green="Grün", Blue="Blau"
3
2432
by: frivard | last post by:
I have a Enum named "Status" with elements like public enum Status : int { T = 82, C = 67, } I want to display de content of this Enum in a combobox. In my combobox i want the attribute to be
2
1615
by: Rene | last post by:
Say that I create a combobox with pull down items that map directly to an enum. For example the dropdown items could be "Up", "Down", "Left" and "Right" and the enum could be declare as: public enum DirectionEnum {Up, Down, Left, Right}; If I needed to get an enum reference based on the dropdown selection, as of today I would do the following: DirectionEnum myEnum; // Declare enum. If(someCombobox.Text == "Up") myEnum ==...
7
11369
by: gwenda | last post by:
I need a datasource for a third party combobox and the data should come from an enum. I have figured out how to use the enum to create a 2-dimensioned array imitating the form of Key, Value such as a DictionaryEntry object would like. But how can I now transform the array into DictionaryEntry object? Or is there a better way to feed an enum to a ComboBox.Datasource? I'm using .NET framework 1.1 and VStudio.
3
36286
by: cyshao | last post by:
Hi ,my friends: I have a enum type ,EMyEnum , defigned as . I just want to do something like this: foreach( EMyEnum crrEnum in EMyEnum ) { //do something }
7
9833
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
3
3646
by: Desmond Cassidy | last post by:
I created an Enum with the EnumBuilder which allows you to add items with spaces embedded as well as the name of the Enum. e.g. US States and a member of New York The normal way you would iterate through an Enum is as follows For Each lstrItem As String In .GetNames(GetType(Geographical.US_States)) Me.Combo.Items.Add(lstrItem) Next But how would you reference an Enum of "US States" ??? * Iknow I could just as easily create an Enum...
5
7644
by: kjqua | last post by:
Hi all, I am newbie in c# and i have a question. I try to work with serial port. and i will like to configure the serial port by a form I add in a ComboBox.parity some items like: None Odd
1
7827
by: Gerrit | last post by:
Hello, I have an enum, example: enum MyEnum { My_Value_1, My_Value_2 }
0
8753
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
9411
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
9265
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
9188
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
9122
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
6012
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
4522
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...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2159
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.