枚举 遍历枚举中所有的值、将某一个值转换成枚举型

来源:互联网 发布:推荐淘宝日用品店铺好 编辑:程序博客网 时间:2024/05/22 06:34

1, 将枚举类型ViewType中所有值遍历,放到coboBox中

            cbeType.Properties.Items.Clear();            cbeType.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;            foreach (ViewType vt in Enum.GetValues(typeof(ViewType)))            {                cbeType.Properties.Items.Add(vt.ToString());            }


2,将coboBox 的某一个选中值转换成枚举型ViewType

        private void cbeType_SelectedValueChanged(object sender, EventArgs e)        {            string sName = "";            if (!Common.IsNullOrEmpty(cbeType.SelectedItem))            {                sName = cbeType.SelectedItem.ToString();                ViewType tmp = (ViewType)(Enum.Parse(typeof(ViewType),sName));                BindData(tmp);//重新绑定数据            }        }


 

原创粉丝点击