ComboBox控制元件 Dictionary載入資料來源
阿新 • • 發佈:2020-10-14
#region [設定ComboBox資料來源] private Dictionary<string, string> GetScoreStatus() { Dictionary<string, string> dic = new Dictionary<string, string> { {"2", "全部"}, {"1", "成功"}, {"0", "失敗"} };return dic; } #endregion #region [繫結ComboBox成績上傳狀態] private void BindComboBox() { ComboBox comboBox = this.toolStripComboBox_ScoreStatus.ComboBox; if (comboBox != null) { BindingSource bs = new BindingSource //宣告BindingSource { DataSource = GetScoreStatus() //繫結Dictionary }; comboBox.DataSource = bs; //繫結BindingSource comboBox.ValueMember = "Key"; comboBox.DisplayMember = "Value"; } }#endregion