定义枚举

        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. 2016.3 idea 注册码

    idea 最新官方版本:2016.3 idea 注册码 1.下载最新idea 下载地址:https://www.jetbrains.com/idea/ 2.安装 Windows 直接下载 .exe 文 ...

  2. 下载Ubuntn 17.04 内核源代码

    zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21-Ubuntu SMP Thu Apr 6 17:04:57 ...

  3. Java Collection 简介

    转自:http://skyuck.iteye.com/blog/526358 在 Java2中,有一套设计优良的接口和类组成了Java集合框架Collection,使程序员操作成批的数据或对象元素极为 ...

  4. lua中遍历table的几种方式比较

    当我在工作中使用lua进行开发时,发现在lua中有4种方式遍历一个table,当然,从本质上来说其实都一样,只是形式不同,这四种方式分别是: for key, value in pairs(tbtes ...

  5. 网络游戏MMORPG服务器架构

    转载于:http://justdo2008.iteye.com/blog/1936795 1.网络游戏MMORPG整体服务器框架,包括早期,中期,当前的一些主流架构 .关键词 网络协议 网络IO 消息 ...

  6. 解析Java的JNI编程中的对象引用与内存泄漏问题

    JNI,Java Native Interface,是 native code 的编程接口.JNI 使 Java 代码程序可以与 native code 交互——在 Java 程序中调用 native ...

  7. 《java 语言程序设计》第3、4章编程练习

    3.1 public class test { public static void main(String[] args) { System.out.println("Enter a, b ...

  8. mysql创建、删除用户与授权(linux測试)

    注:我的执行环境是SUSE Linux + mysql5.6 一.创建用户:  命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password';  ...

  9. 构建高可用Linux服务器一

    1.显示物理CPU个数:cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -1 2.显示每个物理CPU中的core ...

  10. Cocos2d-x -- 图片菜单按钮

    Scene* MainMenu::createScene() { // 'scene' is an autorelease object auto scene = Scene::create(); / ...