Winform Comobox 绑定 Dictionary数据源

使用BindingSource进行间接绑定

    Dictionary<string ,string> dic=new Dictionary<string,string>();
            BindingSource bs = new BindingSource();     //声明BindingSource
            
            dic.Add("GROUP_NAME","工序名称");
            dic.Add("TEST_ITEM_NAME", "测试项目名称");
            dic.Add("PERSON_MODIFY", "修改人");

            bs.DataSource = dic;        //绑定Dictionary

            this.cbb_ChooseItem.DataSource = bs;    //绑定BindingSource
            this.cbb_ChooseItem.ValueMember = "Key";
            this.cbb_ChooseItem.DisplayMember = "Value";

使用:

string chooseItem = this.cbb_ChooseItem.SelectedValue.ToString();

posted @ 2018-12-27 14:18  hanje  阅读(489)  评论(0)    收藏  举报