enum 绑定到combobox并获取

 1         public enum MyEnum 
 2         { 
 3             [Description("S117200")]
 4             S71200 = 1,
 5             [Description("S117300")]
 6             S71300 = 2,
 7             [Description("S117400")]
 8             S71400 = 3,
 9             [Description("S117500")]
10             S71500 = 4
11         }
12 
13         public void Form1_Load(object sender, EventArgs e)
14         {
15             //绑定
16             cbx_type.Items.AddRange(Enum.GetNames(typeof(MyEnum)));
17         }
18 
19         private void button1_Click(object sender, EventArgs e)
20         {
21             //获取
22             MyEnum me = (MyEnum)Enum.Parse(typeof(MyEnum), (cbx_type.SelectedIndex + 1).ToString());
23         }

猜你喜欢

转载自www.cnblogs.com/czicy/p/9342154.html