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