Find the Value of an Enumeration


Author
Message
Terry Bottorff
Terry Bottorff
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 448, Visits: 12K
I have a very simple enumeration

public enum paytype

cash = 1

check = 2

other = 3

end enum

I fill a combo box on my win form with the enum but Not Bound to a BO.

It shows cash and so forth the way I want but is there a way to get the value of the one selected?

Say person selects check, how do I get 2?

Probably easy but not clicking today....

TIA.
Replies
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
You are welcome Terry.

But on my form if a person selects Check from the ComboBox how does one figure what value the selected enumeration has?
  • If the combobox is binded to a field via the BindingField and BusinessObject properties, then whenever an item is selected from the combobox, this bo.Field will contain the value of the enumeration, in your case will be the number 2.
  • If the  combobox is not binded, then simply cast its SelectedValue to the enum type and do your validation.  Something like this:

        Dim bEnum As PayTypes = CType(Me.cbxpaytypes.SelectedValue, PayTypes)
         Select Case bEnum
             Case PayTypes.Cash
                 MessageBox.Show("You selected cash")
             Case PayTypes.Check
                 MessageBox.Show(String.Format("You selected {0}", MicroFour.StrataFrame.Tools.Common.GetEnumDisplayValue(bEnum)))
             Case PayTypes.Other
                 MessageBox.Show("You selected Other")
         End Select



Edhy Rijo

Edited 13 Years Ago by Edhy Rijo
Terry Bottorff
Terry Bottorff
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 448, Visits: 12K
Thanks Edhy that will work.

I tried using Ctype but since I don't exactly have all the experience I need I just could not get the syntax correct. Once I saw it, it made sense but I could not produce it. I think my problem was I did not know what type I was trying to convert to what type.

Again thank you so much for such great help.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search