其他分享
首页 > 其他分享> > ComboBox控件 Dictionary加载数据源

ComboBox控件 Dictionary加载数据源

作者:互联网

 

  #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

 

标签:控件,Dictionary,数据源,绑定,comboBox,ComboBox,BindingSource
来源: https://www.cnblogs.com/yunchen/p/13814769.html