http://www.cnblogs.com/refresh/archive/2012/07/14/2591503.html

https://msdn.microsoft.com/zh-cn/library/system.windows.forms.bindingsource(v=vs.80).aspx

ComboBox的DataSource的值可设置为 :实现 IList 接口的对象,如 DataSet 或 Array。默认为 空引用(在 Visual Basic 中为 Nothing)。

但是在实际的项目中可能需要绑定Dictionary作为数据源。此时,将Dictionary<>放到BindingSource中便可以实现间接绑定。

BindingSource 组件有两种用途:

首先,它通过提供一个间接寻址层、当前项管理、更改通知和其他服务简化了窗体中控件到数据的绑定。这是通过将 BindingSource 组件附加到数据源,然后将窗体中的控件绑BindingSource 组件来实现的。与数据的所有进一步交互,包括定位、排序、筛选和更新,都通过调用 BindingSource 组件实现。

第二,BindingSource 组件可以作为一个强类型的数据源。通常,基础数据源的类型通过以下机制之一固定: 使用 Add 方法可将某项添加到 BindingSource 组件中。 将 DataSource 属性设置为一个列表、单个对象或类型。 这两种机制都创建一个强类型列表。BindingSource 支持由其 DataSource 和 DataMember 属性指示的简单数据绑定和复杂数据绑定。

有关BindingSource的更详细信息请参考:http://msdn.microsoft.com/zh-cn/library/system.windows.forms.bindingsource(VS.80).aspx 示例代码如下:

1 Dictionary<string, string> dic = new Dictionary<string, string>();
2 BindingSource bs = new BindingSource();
3 bs.DataSource = dic;
4 cbb.DataSource = bs;
5 cbb.DisplayMember = "Value";
6 cbb.ValueMember = "Key";

ComboBox绑定Dictionary做为数据源的更多相关文章

  1. 下拉列表框DropDownList绑定Dictionary泛型类

    DropDownList绑定Dictionary泛型类 定义一个Dictionary泛型类 /// <summary>    /// 产品类型    /// </summary> ...

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

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

  3. 多个ComboBox绑定同一个数据源出现的问题解决办法

    出现问题: 当多个ComboBox绑定同一个数据源后,只要更改其中一个的选择项时,其它的ComboBox也跟着改变了 解决办法: DataTable dt = new DataTable(); dt ...

  4. ListBox和ComboBox绑定数据简单例子

    1. 将集合数据绑定到ListBox和ComboBox控件,界面上显示某个属性的内容 //自定义了Person类(有Name,Age,Heigth等属性) List<Person> per ...

  5. C#ComboBox绑定List

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

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

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

  7. silverlight中 ComboBox绑定数据库,并获取当前选定值

    silverlight中 ComboBox绑定数据库,并获取当前选定值 在silverlight中 用combobox下拉菜单绑定数据库的方法和用DataGrid绑定数据库的方法类似. page.xa ...

  8. Combobox绑定泛型字典时提示“复杂的 DataBinding 接受 IList 或 IListSource 作为数据源”的解决方法

    一般情况下我们会将 DataTable 或 DataView 绑定到 Combobox 控件上,这时候进行数据绑定是没有问题的,因为DataTable 和 DataView 都继承了 IList 接口 ...

  9. comboBox绑定字典Dictionary 获取value中的值

    第一种 最简洁的方法 Dictionary<string, string> list = new Dictionary<string, string> { {"thi ...

随机推荐

  1. mac安装软件系列

    1,mac安装homebrew,注意不能用root权限安装 #ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew ...

  2. centsOS下安装vsftp的配置

    1. 添加用户组 # groupadd www 2. 修改配置 # vi /etc/vsftpd/vsftpd.conf 查找: #chroot_list_enable=YES #chroot_lis ...

  3. http验证CertificateValidation

    private void btnopenURL_Click(object sender, EventArgs e) { string strUrl = txtopenURL.Text.Trim(); ...

  4. line-height:2、line-height:2em、line-height:200%的区别

    文章来源: http://www.zhihu.com/question/20394889 总结: 1.line-height:2em.line-height:200%  根据父元素的字体大小计算行高 ...

  5. HDU 2544 最短路(初涉SPFA算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t ...

  6. HDU 2181 哈密顿绕行世界问题

    Problem Description 一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市. Input 前20行的第i行有3个数, ...

  7. page,request,session,application四个域对象的使用及区别

    转自:page,request,session,application四个域对象的使用及区别 1.page指当前页面.只在一个jsp页面里有效 .2.request 指从http请求到服务器处理结束, ...

  8. Ctrl+Alt+T恢复启动Ubuntu默认终端

    对于Ubuntu14.04,如果安装了terminator,那么快捷键Ctrl+Alt+T将不会启动自带的terminal,而是启动安装的terminator,如果想恢复回来,可以执行以下命令: su ...

  9. Amazon EC2 的名词解释

    Amazon EC2   Amazon Elastic Compute Cloud (Amazon EC2) Amazon EC2 提供以下功能: 实例:虚拟计算环境 实例预配置模板/Amazon 系 ...

  10. Struts2配置文件动态传参

    两个Action动态传递参数: 1.从一个Action传递到另一个Action如果带有参数那么result中的type属性需要使用redirect 第一个Action代码如下: private Str ...