enum and combobox

F

Franky

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
 
M

Mark White

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
 
R

Roger

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
 
M

Mark White

Yes, as long as it supports the IList interface, you can just databind the
array that is returned to the combobox.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top