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; }  
}  

补充: checkedComboBoxEdit 多选设置

反绑定 重点:

DevExpress.XtraEditors.CheckedComboBoxEdit  cmb_check_CKID = new DevExpress.XtraEditors.CheckedComboBoxEdit();

   private void GetAllCK()
        {
            List<TB_STORE> list = (List<TB_STORE>)serviceLocator.GetService<ITB_STOREBLL>().GetAllStore(StaticUser.ConmanyID);//LISt数据源
            cmb_check_CKID.Properties.DataSource = list;
            cmb_check_CKID.Properties.DisplayMember = "STORENAME";
            cmb_check_CKID.Properties.ValueMember = "ID";
            cmb_check_CKID.Properties.SeparatorChar = ','; //逗号 隔开   存储的 值是 编号(ID)如 2,3,4
        }
 
this.cmb_check_CKID.RefreshEditValue();//反绑定 的 时候 这句 很重要


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值