第一种 最简洁的方法

Dictionary<string, string> list = new Dictionary<string, string> { {"this is i1", "001"}, {"this is i2", "002"} };

private void Form1_Load(object sender, EventArgs e) {

comboBox1.Items.AddRange(list.Keys.ToArray());

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

string a = list[comboBox1.SelectedText];

textBox1.Text = a;

}

第二种 笨点的方法

绑定数据

private void Form1_Load(object sender, EventArgs e) {

var list = new Dictionary<string, string> { {"this is i1", "001"}, {"this is i2", "002"} };

comboBox1.Items.AddRange(new object[] {list.ToArray()});

comboBox1.DisplayMember = "key";

comboBox1.ValueMember = "value";

}

//绑定数据 以上方法失效用这个方法
Dictionary<string, string> dict = new Dictionary<string, string> {{"baidu.com", "百度"}, {"goolge.com", "谷歌"}, {"qq.com", "腾讯"}};
comboBox1.DataSource = new BindingSource(dict, null);
comboBox1.ValueMember = "Key";//文本对应的值
comboBox1.DisplayMember = "Value";//显示的文本

获取值

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

string a = ((KeyValuePair<string, string>)comboBox1.SelectedItem).Value;

textBox1.Text = a;

}

comboBox绑定字典Dictionary 获取value中的值的更多相关文章

  1. c#字典怎么获取第一个键值 List<对象>获取重复项,转成Dictionary<key,List<对象>>

    c#字典怎么获取第一个键值 Dictionary<string, int> dictionary = new Dictionary<string, int>(); dictio ...

  2. 安卓Android控件ListView获取item中EditText值

    可以明确,现在没有直接方法可以获得ListView中每一行EditText的值. 解决方案:重写BaseAdapter,然后自行获取ListView中每行输入的EditText值. 大概算法:重写Ba ...

  3. ThinkPHP 获取配置文件中的值

    C('SPECIAL_USER'):获取配置文件中的值 存入数组

  4. 通过YAJL获取json中的值

    这里主要是举例说明一下假设通过yajl获取json中的值. 对于array和object来说,获取的方式略有不同,详细能够參考以下的代码. 我仅仅是从网上搜集信息.知道有这么一种方法.假设还有别的方法 ...

  5. jQuery遍历table中的tr td并获取td中的值

    jQuery遍历table中的tr td并获取td中的值 $(function(){ $("#tableId tr").find("td").each(func ...

  6. Android控件ListView获取item中EditText值

    能够明白,如今没有直接方法能够获得ListView中每一行EditText的值. 解决方式:重写BaseAdapter,然后自行获取ListView中每行输入的EditText值. 大概算法:重写Ba ...

  7. VUE中获取url中的值

    如图:获取值 一:main.js中写入 const router = new VueRouter({ routes: [ { path: '/goodsinfo/:goodsId', componen ...

  8. React 修改获取state中的值

    14===> 修改state中的值 不能够直接修改 state = { num: 10 } 如 this.state.num+=12; 不能够直接修改 错误 通过 this.setState({ ...

  9. selenium+java:获取列表中的值

    selenium+java:获取列表中的值 (2011-08-23 17:14:48) 标签: 杂谈 分类: selenium 初步研究利用java+testNg框架下写selenium测试用例,今天 ...

随机推荐

  1. unity, Invoke延迟执行

    参考:http://blog.christianhenschel.com/2013/05/15/how-to-do-delayed-function-calls-in-unity3d-one-line ...

  2. Debian run jar like a native program

    sudo apt install binfmt-support jarwrapper 比如 swagger-codegen wget -O ~/.local/bin/swagger-codegen h ...

  3. 一个简单的servlet容器

    [0]README 0.1)本文部分文字转自 “深入剖析Tomcat”,旨在学习  一个简单的servlet容器  的基础知识: 0.2)for complete source code, pleas ...

  4. freemark 页面静态化

    1. 页面静态化是什么? 页面静态化有非常多含义,在WEB开发中.静态网页一般理解为站点中大部分超级链接所引用的页面是单独的HTML静态页面文件(如.htm..html等页面文件,html语言本身是静 ...

  5. KMP hihoCoder1015 KMP算法

    人太蠢,,看了一天的KMP.. 刚開始看训练指南的,,后来才惊奇的发现原来刘汝佳写的f数组并非Next数组! 总认为和之前看过的全然不一样.. . 后来又百度了一下KMP,研究了非常久,然后用自己的逻 ...

  6. php 打印debug日志

    A lesser known trick is that mod_php maps stderr to the Apache log. And, there is a stream for that, ...

  7. RMI 连接超时时间设定

    System.setProperty("sun.rmi.transport.tcp.responseTimeout", "2000"); System.setP ...

  8. asp.net C#实现下载文件的六种方法实例

    protected void Button1_Click(object sender, EventArgs e)  {  /*  微软为Response对象提供了一个新的方法TransmitFile来 ...

  9. Editor编辑器的一些用法

    共有两个脚本,一个是有关Inspector面板的,一个是window的 using UnityEngine; using System.Collections; using UnityEditor; ...

  10. PYTHON --WebAPP项目转载(廖雪峰) -- Day 1 -- 搭建开发环境

    Day 1 - 搭建开发环境   搭建开发环境 首先,确认系统安装的Python版本是3.5.x: $ python3 --version Python 3.5.1 然后,用pip安装开发Web Ap ...