473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Filling combobox with enumeration values

How would I go about filling a combo box with some existing enumeration
values? Can I bind it to the enumeration? Then, once the selection is made
from the combo box, set a property to the enumeration value?

Dave

Nov 21 '05 #1
5 9949
"Dave" <dave@4_rem_ove_scotts.com> schrieb:
How would I go about filling a combo box with some existing enumeration
values? Can I bind it to the enumeration? Then, once the selection is made
from the combo box, set a property to the enumeration value?


\\\
Private Sub Form1_Load( _
ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
Me.ListBox1.DataSource = _
[Enum].GetNames(GetType(KnownColor))
End Sub

Private Sub ListBox1_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles ListBox1.SelectedIndexChanged
Me.ListBox1.BackColor = _
Color.FromKnownColor( _
DirectCast( _
[Enum].Parse( _
GetType(KnownColor), _
CStr(ListBox1.SelectedItem) _
), _
KnownColor _
) _
)
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Hi,

Enum.GetNames

ComboBox1.Items.AddRange(MyEnum.GetNames(GetType(M yEnum)))

http://msdn.microsoft.com/library/de...namestopic.asp

Ken

------------------------

"Dave" <dave@4_rem_ove_scotts.com> wrote in message
news:eS**************@TK2MSFTNGP11.phx.gbl...
How would I go about filling a combo box with some existing enumeration
values? Can I bind it to the enumeration? Then, once the selection is made
from the combo box, set a property to the enumeration value?

Dave


Nov 21 '05 #3
Thanks Herfried,

That will be very useful!!

Dave

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
"Dave" <dave@4_rem_ove_scotts.com> schrieb:
How would I go about filling a combo box with some existing enumeration
values? Can I bind it to the enumeration? Then, once the selection is
made from the combo box, set a property to the enumeration value?


\\\
Private Sub Form1_Load( _
ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
Me.ListBox1.DataSource = _
[Enum].GetNames(GetType(KnownColor))
End Sub

Private Sub ListBox1_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles ListBox1.SelectedIndexChanged
Me.ListBox1.BackColor = _
Color.FromKnownColor( _
DirectCast( _
[Enum].Parse( _
GetType(KnownColor), _
CStr(ListBox1.SelectedItem) _
), _
KnownColor _
) _
)
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Dave,
In addition to the other comments, I normally bind to the values of an Enum,
rather then the Names of an Enum.

Private Sub Form1_Load( _
ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
'Me.ListBox1.DataSource = _
' [Enum].GetValues(GetType(KnownColor))

Me.ListBox1.DataSource = _
[Enum].GetValues(GetType(FormBorderStyle))

End Sub

Private Sub ListBox1_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles ListBox1.SelectedIndexChanged
'Me.ListBox1.BackColor = _
' Color.FromKnownColor( _
' DirectCast(ListBox1.SelectedItem, KnownColor) _
' )
Me.FormBorderStyle = _
DirectCast(ListBox1.SelectedItem, FormBorderStyle)
End Sub

Either names or values are equally easy, its largely personally choice...

Hope this helps
Jay

"Dave" <dave@4_rem_ove_scotts.com> wrote in message
news:eS**************@TK2MSFTNGP11.phx.gbl...
How would I go about filling a combo box with some existing enumeration
values? Can I bind it to the enumeration? Then, once the selection is made
from the combo box, set a property to the enumeration value?

Dave

Nov 21 '05 #5
On Wed, 8 Dec 2004 14:56:15 -0500, Ken Tucker [MVP] wrote:

ComboBox1.Items.AddRange(MyEnum.GetNames(GetType(M yEnum)))


IMHO, it's better not to call shared methods using the variable name. i.e.
I think it is better to use this:

ComboBox1.Items.AddRange([Enum].GetNames(GetType(MyEnum)))

Note the use of [Enum] instead of MyEnum. To me this reinforces the idea
that the GetNames function is not an instance method but a shared one.

Just my 2c
--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #6

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

Similar topics

5
by: -elniniol999- | last post by:
I am DESPERATE for a quick reply.. have exhausted my options... i have a table called order details which contains: order id product id product name quantity unit price sale price
1
by: reidarT | last post by:
I am filling a combobox with data from a table. This is done with the code below. After update of the combobox I want to fill txtField2 with data from Field2 in the select-statement. How can I do...
27
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to...
3
by: Franky | last post by:
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, }
2
by: fstenoughsnoopy | last post by:
I have a customer order database and I need to pull a customers information, ie first name, last name, address, city, state, zip, phone, etc, into the oder table. i don't know how to go about...
1
by: NvrBst | last post by:
I have a dropdown list, then right now I simply call BGColorComboBox.DataSource = Enum.GetValues(typeof(KnownColor)); BGColorComboBox.SelectedItem = KnownColor.Black; Which works great except...
1
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
Is there a quick way to preload a ComboBox with all values of an Enumeration? Either in VS.2005 Designer or at run time. In my case the combobox is bound to a property of a business object. ...
6
by: phytorion | last post by:
idk why this is giving me such a problem but here it is. I need to add a combobox to a continuous form. This combobox needs to allow the user to select between "S" and "T" for each record in this...
0
by: puvit82 | last post by:
My problem is as follows, any advice / suggestion would be greatly appreciated: Lets suppose that I have defined a simpleType "addressType" with 3 enumeration values (Home, Office, Vacation)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.