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();

猜你喜欢

转载自www.cnblogs.com/hanje/p/10184719.html