1、效果圖:
2、界面拖一個gridLookUpEdit控件點擊designer views進入界面,如圖:
a、先創建下拉網格顯示的列數據:
復選框列設置:caption:列頭顯示、tag設置為chenkbox
b、上圖columnedit選擇的數據設置:
c、網格顯示設置:
views→GridView1→OptionsCustomization→AllowFilter=false //關掉條件過濾
views→GridView1→OptionsCustomization→AllowSort=false //關掉排序
views→GridView1→OptionsMenu→EnableColumnMenu = False //關掉列菜單
《多選重點來了》
views→GridView1→OptionsSelection→EnableAppearanceFocusedCell = False //關掉列焦點
views→GridView1→OptionsSelection→MultiSelect = True // 開啟多選
views→GridView1→OptionsSelection→MultiSelectMode =RowSelect //默認不變
views→GridView1→OptionsView→ShowGroupPanel = False
views→GridView1→FocusRectStyle=RowFocus
this.gridLookUpEdit1.CustomDisplayText += new DevExpress.XtraEditors.Controls.CustomDisplayTextEventHandler(gridLookUpEdit1_CustomDisplayText); this.gridLookUpEdit1.Properties.DataSource = list; //列表數據 this.gridLookUpEdit1.Properties.DisplayMember = "wo_no"; //綁定Text顯示的字段源名稱 this.gridLookUpEdit1.Properties.ValueMember = "wo_no"; //綁定Value字段源名稱
可視化設置已經完成,想要實現多選還要代碼
//工單下拉選項選中索引
IList<int> rowsIndex = new List<int>();
//定義修改進入驗證
bool edit_flag = false;
//定義修改進入的工單賦值
string wo_text = "";
///gridLookUpEdit文本框顯示的內容
private void gridLookUpEdit1_CustomDisplayText(object sender, CustomDisplayTextEventArgs e) { if (edit_flag) {//驗證是否是修改進入的賦值 e.DisplayText = wo_text; } else { if (rowsIndex.Count > 0) { int[] rows = rowsIndex.ToArray(); if (rows != null) { List<string> listname = new List<string>(); foreach (int r in rows) { string name = gridView1.GetRowCellValue(r, "wo_no").ToString(); listname.Add(name); } string text = string.Join(",", listname); e.DisplayText = text.ToString(); } } else { e.DisplayText = ""; } } }
///列表選中事件 private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { if (ActiveControl is GridLookUpEdit) { //(ActiveControl as GridLookUpEdit).Text = " "; } }
///列表一行列單擊事件 private void gridView1_RowCellClick(object sender, RowCellClickEventArgs e) { WorkOrder wo = new WorkOrder(); int index = this.gridView1.FocusedRowHandle; wo = gridView1.GetRow(index) as WorkOrder; if (wo == null) { MessageDialog.ShowTips("請選中一行!"); return; } if (e.Column.Tag != null && e.Column.Tag.ToString() == "chenkbox") { int selectIndex = this.gridView1.FocusedRowHandle; edit_flag = false;//修改進入標識變更 WorkOrder row = this.gridView1.GetRow(selectIndex) as WorkOrder; if (row != null) { DevExpress.Data.CustomSummaryEventArgs e1 = new DevExpress.Data.CustomSummaryEventArgs(); row.CheckboxSelectorColumn = !row.CheckboxSelectorColumn; if (rowsIndex.Count <= 0) { if (row.CheckboxSelectorColumn) rowsIndex.Add(selectIndex); } else { if (rowsIndex.Contains(selectIndex) && !row.CheckboxSelectorColumn)//包含並為false,移除 rowsIndex.Remove(selectIndex); if (!rowsIndex.Contains(selectIndex) && row.CheckboxSelectorColumn)//不包含並為true,添加 { bool select = false; foreach (int r in rowsIndex) { WorkOrder woTemp = this.gridView1.GetRow(r) as WorkOrder; if (woTemp.material_no == row.material_no) { rowsIndex.Add(selectIndex); select = true; break; } } gridView1.SetRowCellValue(selectIndex, "CheckboxSelectorColumn", select); } } (ActiveControl as GridLookUpEdit).Text = " "; } this.gridView1.RefreshData(); } }