comboBox绑定字典Dictionary 获取value中的值
第一种 最简洁的方法
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中的值的更多相关文章
- c#字典怎么获取第一个键值 List<对象>获取重复项,转成Dictionary<key,List<对象>>
c#字典怎么获取第一个键值 Dictionary<string, int> dictionary = new Dictionary<string, int>(); dictio ...
- 安卓Android控件ListView获取item中EditText值
可以明确,现在没有直接方法可以获得ListView中每一行EditText的值. 解决方案:重写BaseAdapter,然后自行获取ListView中每行输入的EditText值. 大概算法:重写Ba ...
- ThinkPHP 获取配置文件中的值
C('SPECIAL_USER'):获取配置文件中的值 存入数组
- 通过YAJL获取json中的值
这里主要是举例说明一下假设通过yajl获取json中的值. 对于array和object来说,获取的方式略有不同,详细能够參考以下的代码. 我仅仅是从网上搜集信息.知道有这么一种方法.假设还有别的方法 ...
- jQuery遍历table中的tr td并获取td中的值
jQuery遍历table中的tr td并获取td中的值 $(function(){ $("#tableId tr").find("td").each(func ...
- Android控件ListView获取item中EditText值
能够明白,如今没有直接方法能够获得ListView中每一行EditText的值. 解决方式:重写BaseAdapter,然后自行获取ListView中每行输入的EditText值. 大概算法:重写Ba ...
- VUE中获取url中的值
如图:获取值 一:main.js中写入 const router = new VueRouter({ routes: [ { path: '/goodsinfo/:goodsId', componen ...
- React 修改获取state中的值
14===> 修改state中的值 不能够直接修改 state = { num: 10 } 如 this.state.num+=12; 不能够直接修改 错误 通过 this.setState({ ...
- selenium+java:获取列表中的值
selenium+java:获取列表中的值 (2011-08-23 17:14:48) 标签: 杂谈 分类: selenium 初步研究利用java+testNg框架下写selenium测试用例,今天 ...
随机推荐
- redis 大内存主从问题解决
redis 内存太大使用太大会导致同步陷入循环,每次rdb还没同步完成,新的同步又起,解决办法: redis-cli config set client-output-buffer-limit &qu ...
- JanusGraph与Cassandra集成模式
//如果使用的是cassandra 2.2或更高版本,需要开启thift,以使janus连接到cassandra. ./bin/nodetool enablethrift. 15.1 Local Se ...
- C# Enum,Int,String,之间及bool与int之间的转换
枚举类型的基类型是除 Char 外的任何整型,所以枚举类型的值是整型值. Enum 提供一些实用的静态方法: (1)比较枚举类的实例的方法 (2)将实例的值转换为其字符串表示形式的方法 (3)将数字的 ...
- vivado与modelsim的联合仿真(一)
vivado软件中也自带仿真工具,但用了几天之后感觉仿真速度有点慢,至少比modelsim慢挺多的.而modelsim是我比较熟悉的一款仿真软件,固然选它作为设计功能的验证.为了将vivado和mod ...
- 初识Quartz(一)
首先需要一个任务: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 package quartz_proj ...
- 学习spring in action 第一天
这段时间,开始学习java吧,因为C sharp 学习了java的大量语法格式,所以,留意下,就不会错了,java 有的c sharp也有,而且之前我也学习过java的桌面开发,但是一下子上来就要自己 ...
- Flex读取txt文件里的内容报错
Flex读取txt文件里的内容 1.详细错误例如以下 2.错误原因 读取文件不存在 var file:File = new File(File.applicationDirectory.nativeP ...
- Silverlight-管理独立存储(Isolated Storage)
Silverlight中的独立存储是其内部的可信任的可访问文件空间,在这里你可以使用Silverlight 随意的创建.读取.写入.删除目录和文件,它有一些类似于Cookie,但是它可以在客户端保存大 ...
- Math函数的"四舍五入",Floor,Ceiling,Round的一些注意事项!
1.Math.Round:四舍六入五取偶 引用内容 Math.Round(0.0) //0Math.Round(0.1) //0Math.Round(0.2) //0Math.Round(0.3) / ...
- ng file上传同域非同域
跨域 vm.uploadFiles = function (file, errFiles) { if (file) { file.upload = Upload.upload({ url: vm.up ...