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         }

 

posted @ 2018-07-20 16:22  岁月就是把猪饲料  阅读(231)  评论(0编辑  收藏  举报