DevExpress_GridLookUpEdit下拉网格数据显示多选操作
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(); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App