结合两个组合框相同的数据源,每个组合都会有个人行为 [英] Binding two combo boxes to the same data source,that each combo will have individual behaviour

查看:158
本文介绍了结合两个组合框相同的数据源,每个组合都会有个人行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,当我第一次在组合框中选择项的第二个模仿的选择。
我希望能够在每个组合框分别选择。
谢谢你。

 列表< W6AdminUIs2.DictionaryObject> taskStatuses = W6AdminUIs2.GlobalFunctions.GetDictionaryItems(TaskStatus);    //初始化的状态的绑定源。
    BindingSource的bsFromStatuses =新的BindingSource();
    bsFromStatuses.DataSource = taskStatuses;    //从组合框绑定到绑定源。
    cBoxFrom.DataSource = bsFromStatuses.DataSource;
    cBoxFrom.DisplayMember =姓名;
    cBoxFrom.ValueMember =键;    //初始化的状态的绑定源。
    BindingSource的bsToStatuses =新的BindingSource();
    bsToStatuses.DataSource = taskStatuses;    //从组合框绑定到绑定源。
    cBoxTo.DataSource = bsToStatuses.DataSource;
    cBoxTo.DisplayMember =姓名;
    cBoxTo.ValueMember =键;


解决方案

我不知道你用的是什么样的词典,但我正常使用的字典,这code不那样做的:

 词典<字符串,字符串>字典=新词典<字符串,字符串>();
dict.Add(S1,样品1);
dict.Add(S2,样品2);
dict.Add(S3,样本3);
dict.Add(S4,Sample4);comboBox1.DataSource =新的BindingSource(字典,NULL);
comboBox1.DisplayMember =值;
comboBox1.ValueMember =钥匙;comboBox2.DataSource =新的BindingSource(字典,NULL);
comboBox2.DisplayMember =值;
comboBox2.ValueMember =钥匙;

Now when i select item in first combo box the second mimic the selection. I want to be able to select in each of the combo boxes individually. Thanks.

 List<W6AdminUIs2.DictionaryObject> taskStatuses = W6AdminUIs2.GlobalFunctions.GetDictionaryItems("TaskStatus");

    // Init the binding source of the statuses.
    BindingSource bsFromStatuses = new BindingSource();
    bsFromStatuses.DataSource = taskStatuses;

    //Bind the "From" combo box to binding source.
    cBoxFrom.DataSource = bsFromStatuses.DataSource;
    cBoxFrom.DisplayMember = "Name";
    cBoxFrom.ValueMember = "Key";

    // Init the binding source of the statuses.
    BindingSource bsToStatuses = new BindingSource();
    bsToStatuses.DataSource = taskStatuses;

    //Bind the "From" combo box to binding source.
    cBoxTo.DataSource = bsToStatuses.DataSource;
    cBoxTo.DisplayMember = "Name";
    cBoxTo.ValueMember = "Key";

解决方案

I don't know what kind of dictionary you are using but i use normal dictionary and this code dont behave like that :

Dictionary<string,string> dict = new Dictionary<string, string>();
dict.Add("S1", "Sample1");
dict.Add("S2", "Sample2");
dict.Add("S3", "Sample3");
dict.Add("S4", "Sample4");

comboBox1.DataSource = new BindingSource(dict, null);
comboBox1.DisplayMember = "value";
comboBox1.ValueMember = "key";

comboBox2.DataSource = new BindingSource(dict, null);
comboBox2.DisplayMember = "value";
comboBox2.ValueMember = "key";

这篇关于结合两个组合框相同的数据源,每个组合都会有个人行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆