enum and combobox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Franky

    #1

    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
  • Mark White

    #2
    Re: enum and combobox

    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" <dries@bestopia .be> wrote in message
    news:1135007257 .191369@seven.k ulnet.kuleuven. ac.be...[color=blue]
    > 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[/color]


    Comment

    • Roger

      #3
      Re: enum and combobox

      > 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


      Comment

      • Mark White

        #4
        Re: enum and combobox

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

        Mark

        "Roger" <roger@pcsreven uecontrol.com> wrote in message
        news:%23W8ZSANB GHA.2356@tk2msf tngp13.phx.gbl. ..[color=blue][color=green]
        > > Use a loop to iterate over and assign to your > combobox.[/color]
        >
        > I think it can be done without the loop.
        > Look it up in the docs.
        > Roger
        >
        >[/color]


        Comment

        Working...