How do I get the value that is in the {}

I have a combobox with its datasource bound to an enumeration.

Now When I look at it the selecteditem and selected value are objects. I don't need the string I need intgere assignes to that string and it looks like this in the debugger value column under locals

RED {1}
BLUE {2}
GREEN {3}

So how do I get the integer.

If I do X = comboBox.selectedValue.GethashCode it works but I don't know if that is the right way.

Is there a way to bind the combobox to the corrected values before I load it

Thanks.



Answer this question

How do I get the value that is in the {}

  • Valkyrie-MT

    If the enum name is Color then you can do something like

    Dim i As Integer = CInt(CType(comboBox.SelectedValue, Color))



  • MLange2064

    Correct, and by adding the structure object to the combobox each entry will contain all of your structure's properties and methods (e.g. you have a color variable of type system.drawing.color):

    Combobox1.Items.Add(New MyStructure("Red",system.drawing.colors.red))

    Or something along those lines :)


  • Samya

    The eaisest way I've found is to create your own structure and load those objects into the combo or list box.

    See this post for an example structure: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=99215&SiteID=1


  • shodan

    Thanks for both answers.

    So with the structure I'll have to loop thru my enums, create a listitem, add it to the combobox and do tihs process for each one correct

     

     

     


  • How do I get the value that is in the {}