定义枚举

        public enum UserLevel
{
Commmon = ,
Administrator,
Developer
}

方法一

        private void Method1()
{
comboBox1.DataSource = System.Enum.GetNames(typeof(UserLevel));
comboBox1.SelectedIndex =
             comboBox1.FindString(UserLevel.Commmon.ToString());
}

方法二

        private void Method2()
{
foreach (var v in typeof(UserLevel).GetFields())
{
if (v.FieldType.IsEnum == true)
{
this.comboBox2.Items.Add(v.Name);
}
}
this.comboBox2.SelectedIndex = ;
}

取值

            UserLevel testenum = (UserLevel)Enum.Parse(typeof(UserLevel), comboBox1.SelectedItem.ToString(), false);
        

c# ComboBox绑定枚举的更多相关文章

  1. c# combobox 绑定枚举方式

    建立一个类 : using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  2. 整理:WPF中Xaml中绑定枚举的写法

    原文:整理:WPF中Xaml中绑定枚举的写法 目的:在Combobox.ListBox中直接绑定枚举对象的方式,比如:直接绑定字体类型.所有颜色等枚举类型非常方便 一.首先用ObjectDataPro ...

  3. DataTrigger 绑定枚举

    在触发器中绑定枚举类型: <ControlTemplate.Triggers> <DataTrigger Binding="{Binding CheckStateEnum} ...

  4. c#中DropDownList控件绑定枚举数据

    c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...

  5. ComboBox绑定数据源时触发SelectedIndexChanged事件的处理办法

    转载:http://blog.sina.com.cn/s/blog_629e606f01014d4b.html ComboBox最经常使用的事件就是SelectedIndexChanged.但在将Co ...

  6. 绑定枚举到dropdownlist

    pageTools.BindEnumToDropdownList(typeof(enumDealerArea), ddlBmwArea, new ListItem("--请选择--" ...

  7. ASP.NET Core 四种方式绑定枚举值

    前言 本节我们来讲讲在ASP.NET Core MVC又为我们提供了哪些方便,之前我们探讨过在ASP.NET MVC中下拉框绑定方式,这节我们来再来重点看看枚举绑定的方式,充分实现你所能想到的场景,满 ...

  8. C#ComboBox绑定List

    ComboBox绑定List时可能会错, public class Person { public string Name; public int Age; public int Heigth; } ...

  9. WPF{ComboBox绑定类对象, 下拉列显示的值,与取到的值}

    DisplayMemberPath 是用来显示下拉列表的值 SelectedValuePath是用来取得选中项的值. ComboBox绑定类对象, 下拉列显示的值,与取到的值 string. Join ...

随机推荐

  1. High-current supply uses standard three-terminal regulator

    Voltage-regulator design for high output currents can be a critical and difficult task. Although vol ...

  2. BOOST Converter Analog/Digital Adjusted Output Voltage TPS61045 MAX1932

    DIGITALLY ADJUSTABLE BOOST CONVERTER The TPS61045 is a high frequency boost converter with digitally ...

  3. rabbitmq 连接測试

    1.假设写错了host (如:factory.setHost("locathost"); )报错: Exception in thread "main" jav ...

  4. js继承——从创建对象开始

    从创建对象开始 创建对象的简单方法就是:使用Object构造函数或者对象字面量.但这两个方法有个缺点:创建相同对象,要编写大量重复代码. 为了避免这个问题——>工厂模式:用函数封装以特定接口创建 ...

  5. 【转】C与CPP后缀的文件在编译时的区别

                                                            本文出处连接, by Ray FAN(ielnaf@qq.com)            ...

  6. java自动识别上传的apk版本号

    import java.util.List; public class ApkInfo { private String versionCode; private String versionName ...

  7. python笔记21-列表生成式

    前言 python里面[]表示一个列表,快速生成一个列表可以用range()函数来生成. 对列表里面的数据进行运算和操作,生成新的列表最高效快速的办法,那就是列表生成式了. range() 1.一个连 ...

  8. java代码逆向工程生成uml

    今天在看一个模拟器的源码,一个包里有多个类,一个类里又有多个属性和方法,如果按顺序看下来,不仅不能对整个模拟器的框架形成一个大致的认识,而且只会越看越混乱,所以,想到有没有什么工具可以将这些个类以及它 ...

  9. php 验证身份证号码

    身份证号码的结构 身份证号码是特征组合码,由17位数字本体码和一位校验码组成. 排列顺序从左至右依此为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码. 地址码(前六位数) 表示编 ...

  10. Redis安装、主从配置及aof使用

    找了02,03,04三台机器,04做主,02做从,03做客户端. 都使用jumbo install redis安装了Redis(server+client). 在 02 从的 ~/.jumbo/etc ...