My problem is that I have a combo box filled with units such as length or weight ie. Inches, Feet, Yard. Or Oz, Lb, Ton. Anyways I have enums such as
public enum Torques {
/// <remarks/>
DyneCentimeters,
/// <remarks/>
FootPounds,
/// <remarks/>
InchPounds,
/// <remarks/>
KilogramMeter,
/// <remarks/>
MeterNewtons,
}
I need an elegant way of grabbing the value out of the drop down and creating a variable of the matching enum type. Right now I am using a case statement such as
Computers fromUnit = Computers.Bit;
switch (compFromUnit.Text)
{
case "Bit":
fromUnit = Computers.Bit;
break;
case "Byte":
fromUnit = Computers.Byte;
break;
case "Kilobyte":
fromUnit = Computers.Kilobyte;
break;
case "Megabyte":
fromUnit = Computers.Megabyte;
break;
case "Gigabyte":
fromUnit = Computers.Gigabyte;
break;
case "Terabyte":
fromUnit = Computers.Terabyte;
break;
case "Petabyte":
fromUnit = Computers.Petabyte;
break;
default:
fromUnit = Computers.Bit;
break;
}
Some of my lists are quite lengthy and to complete the project in this manner would call for some very long case statements. I know there must be some way of completing this all in one line of code.
When I try to assign a value to a selection such as combo.selected.Text = "Bit" combo.selected.Value = "Computers.Bit" and then say something like toUnit = combo.selected.value is says it cannot convert from string.