Loading

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

 

 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedValue is string)
            {
                string selectText = comboBox1.SelectedValue.ToString();
            }
           
            
        }

 

posted @ 2020-10-14 14:31  云辰  阅读(244)  评论(0编辑  收藏  举报