ComboBoxEdit 设置选项值

lookupedit 设置选项值:

 

 

private void LookUpEditFormTest_Load(object sender, EventArgs e)
        {
            IList<Hiscashs> list = HiscashsService.GetTableCovList();
            this.comboBoxEdit1.Properties.DataSource = list;
            this.comboBoxEdit1.Properties.DisplayMember = "EN_CURRENT_BALANCE";
            this.comboBoxEdit1.Properties.ValueMember = "I_ENTER_DATE";


            comboBoxEdit1.Properties.Columns.Add(new LookUpColumnInfo("I_ENTER_DATE", "日期", 20));
            comboBoxEdit1.Properties.Columns.Add(new LookUpColumnInfo("EN_CURRENT_BALANCE", "当前金额", 80));
            //comboBoxEdit1.ItemIndex = 0;//选择第一项
            comboBoxEdit1.ItemIndex = -1;  //无选项,此时显示的是nulltext值 其实这个地方只要editvalue==null,lookupedit就显示nulltext

        }

        private void comboBoxEdit1_EditValueChanged(object sender, EventArgs e)
        {
            string name = this.comboBoxEdit1.SelectedText;
            string value = this.comboBoxEdit1.EditValue.ToString();//自动搜索datasouse,选择与之匹配的值,没有的情况下赋值null ,value的值必须与valuemember的数据类型一致。
            MessageBox.Show(name+"==="+value);
        }

 

 

 

checkedComboBoxEdit 设置选项值

 

        public void TestFunc()
        {
            for (int i = 0; i < IniFunc().Count; i++)
            {
                if (IniFunc()[i].Isno == true)
                    checkedComboBoxEdit1.Properties.Items.Add(i, IniFunc()[i].Name, CheckState.Checked, true);
                else
                    checkedComboBoxEdit1.Properties.Items.Add(i, IniFunc()[i].Name, CheckState.Unchecked, true);
            }

            //取消第二列的选中状态
            checkedComboBoxEdit1.Properties.Items[1].CheckState = CheckState.Unchecked;
            //checkedComboBoxEdit1
            MessageBox.Show(this.checkedComboBoxEdit1.SelectedText + "===" + this.checkedComboBoxEdit1.EditValue.ToString());
        }



        public BindingList<Data> IniFunc()
        {
            BindingList<Data> bindlist = new BindingList<Data>();
            bindlist.Add(new Data { ID = 1, Name = "科比", Isno = true });
            bindlist.Add(new Data { ID = 2, Name = "艾佛森", Isno = false });
            bindlist.Add(new Data { ID = 3, Name = "姚明", Isno = false });
            bindlist.Add(new Data { ID = 4, Name = "韦德", Isno = true });
            bindlist.Add(new Data { ID = 5, Name = "詹姆斯", Isno = true });
            return bindlist;
        }
    }

    public class Data
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public bool Isno { get; set; }
    }
 

 

你可能感兴趣的:(combobox)