網上搜索的 例子 加 自己的 一點點補充
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); } /* 何問起 hovertree.com */
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; } } /* 何問起 hovertree.com */
補充: 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);//<span style="color:#FF0000;"><strong>LISt數據源</strong></span> cmb_check_CKID.Properties.DataSource = list; cmb_check_CKID.Properties.DisplayMember = "STORENAME"; cmb_check_CKID.Properties.ValueMember = "ID"; cmb_check_CKID.Properties.SeparatorChar = ','; //<span style="color:#FF0000;">逗號 隔開</span> 存儲的 值是 編號(ID)如 2,3,4 } this.cmb_check_CKID.RefreshEditValue();//反綁定的 時候 這句很重要 /* 何問起 hovertree.com */