Winform Comobox 繫結 Dictionary資料來源
阿新 • • 發佈:2018-12-27
使用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();