1首先是如何自定义枚举
public enum ClassType
{
拉森钢板桩=1,围檩,支撑//枚举编号从1开始
}
2,将 枚举转换为 数组 然后挂接到combox下
ComboBox cbo = new ComboBox();
cbo.DataSource = System.Enum.GetNames(typeof(TestEnum)); //绑定
ClassTypetestenum = (ClassType)Enum.Parse(typeof(ClassType) ,cbo.SelectedItem.ToString() ,false) //取值
3.获取到对应的枚举下的值(对应的枚举值)
string enumStringTwo = Enum.GetName(typeof(ClassType), model);//推荐
4.获取枚举下的index值
int enumValueTwo = (int)model;
5.值转枚举(string 值 转换为 Enum)
// 值转枚举
Color enumTwo = (ClassType)value
Color enumThree = (ClassType)Enum.ToObject(typeof(ClassType), value);
ClassType ClassTypetestenum = (ClassType)Enum.Parse(typeof(ClassType) ,cbo.SelectedItem.ToString() ,false) //元素值获取到当前枚举值