自定义GridLookUpEdit编辑器
本文版权归博主 惊梦无痕 所有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作。SourceLink
前两天分享了GridControl的自定义编辑器,今天再来分享一下整理出来的GridLookUpEdit的自定义编辑器。
本代码用的DevExpress版本号:17.2.6.0,旧的版本可能有些地方会有些微的变化。
该自定义编辑器需要用到上篇中定义的MyGridView(具体代码可在自定义GridControl编辑器一文中阅览),此控件包含了多列模糊查询功能,希望对使用或正在学习DevExpress的同学有所帮助。
后续有时间会陆续将一些比较实用的自定义编辑器分享出来。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using Comteck.Dto;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Drawing;
using DevExpress.XtraEditors.Popup;
using DevExpress.XtraEditors.Registrator;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base; namespace Comteck.Winforms.Controls {
/// <summary>
/// 自定义的GridLookupEdit,允许进行多列的匹配
/// <para>参照:https://www.devexpress.com/Support/Center/Example/Details/E1985 </para>
/// </summary>
[ToolboxItem(true)]
public class MyGridLookUpEdit : GridLookUpEdit {
/// <summary>
/// 自动注册下拉框编辑器
/// </summary>
static MyGridLookUpEdit() {
RepositoryItemMyGridLookUpEdit.RegisterCustomGridLookUpEdit();
} /// <summary>
/// 创建自定义GridLookupEdit
/// </summary>
public MyGridLookUpEdit() : base() {
Initialize();
} /// <summary>
/// 初始化
/// </summary>
private void Initialize() {
this.Tag = false; // 设置全选标记
this.Properties.AllowMouseWheel = false;
//this.EnterMoveNextControl = true;
this.Properties.ImmediatePopup = true;
this.Properties.TextEditStyle = TextEditStyles.Standard; #region 编辑框默认自动全选 // 鼠标移入文本编辑框触发事件
this.Enter += (sender, e) => {
// 设置全选标记
this.Tag = true;
this.SelectAll();
};
// 获取输入焦点时自动全选
this.MouseUp += (sender, e) => {
// 如果鼠标左键操作并且标记存在,则执行全选
if (e.Button == MouseButtons.Left && (bool)this.Tag) {
this.SelectAll();
} // 取消全选标记
this.Tag = false;
};
// 双击输入框时自动全选
this.DoubleClick += (sender, e) => {
this.SelectAll();
}; #endregion this.KeyDown += this.MyGridLookUpEdit_KeyDown;
} /// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyGridLookUpEdit_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Delete) {
var control = sender as BaseEdit;
if (control.ReadOnly) { return; }
control.EditValue = null;
e.Handled = true;
} else if (e.KeyCode == Keys.Down) {
this.ShowPopup(); e.Handled = true;
} else if (e.KeyCode == Keys.Back) {
if (this.IsPopupOpen == false) {
this.ShowPopup(); e.Handled = true;
}
}
} /// <summary>
/// 自定义编辑器名称
/// </summary>
public override string EditorTypeName => RepositoryItemMyGridLookUpEdit.MyGridLookUpEditName; /// <summary>
/// 重写下拉框编辑器
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemMyGridLookUpEdit Properties => base.Properties as RepositoryItemMyGridLookUpEdit; //
// 摘要:
// Gets or sets whether focus is moved to the next control (according to the tab
// order) when an end-user presses ENTER.
[DefaultValue(true)]
[DXCategory("Behavior")]
public override bool EnterMoveNextControl { get; set; } = true; /// <summary>
///
/// </summary>
/// <returns></returns>
protected override PopupBaseForm CreatePopupForm() {
return new MyGridLookUpPopupForm(this);
} /// <summary>
///
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
public override bool IsNeededKey(KeyEventArgs e) {
return this.Properties.IsNeededKey(e.KeyData);
} /// <summary>
/// 正常情况下,在输入第一个字符(主要是数字及字母)后,虽然自动弹出了下拉框并过滤了数据,
/// 但是此时光标并未定位到下拉框中,导致回车后并未返回匹配到的首行记录
/// 此处就是为了解决以上问题,展开下拉框时自动定位到首行
/// </summary>
protected override void OnPopupShown() {
base.OnPopupShown(); BeginInvoke(new Action(() => {
if (this.GetSelectedDataRow() == null) {
this.Properties.View.FocusedRowHandle = ;
}
}));
}
} /// <summary>
/// 匹配自定义编辑器的下拉GridLookUpEdit
/// </summary>
[DXCategory("Properties")]
[UserRepositoryItem("RegisterMyGridLookUpEdit")]
public class RepositoryItemMyGridLookUpEdit : RepositoryItemGridLookUpEdit {
/// <summary>
/// 编辑器的名称
/// </summary>
public const string MyGridLookUpEditName = "MyGridLookUpEdit"; /// <summary>
/// 注册编辑器
/// </summary>
static RepositoryItemMyGridLookUpEdit() {
RegisterCustomGridLookUpEdit();
} /// <summary>
/// 创建自定义的编辑器
/// </summary>
public RepositoryItemMyGridLookUpEdit() {
// 不允许自动完成
base.AutoComplete = false;
} /// <summary>
/// 编辑器名称
/// </summary>
public override string EditorTypeName => MyGridLookUpEditName; /// <summary>
/// 注册编辑器
/// </summary>
public static void RegisterCustomGridLookUpEdit() {
EditorRegistrationInfo.Default.Editors.Add(
new EditorClassInfo(
MyGridLookUpEditName,
typeof(MyGridLookUpEdit),
typeof(RepositoryItemMyGridLookUpEdit),
typeof(GridLookUpEditBaseViewInfo),
new ButtonEditPainter(),
true));
} /// <summary>
/// 创建自定义GridView
/// </summary>
/// <returns></returns>
protected override ColumnView CreateViewInstance() {
return new MyGridView();
} /// <summary>
/// 创建自定义GridControl
/// </summary>
/// <returns></returns>
protected override GridControl CreateGrid() {
return new MyGridControl();
}
} public class MyGridLookUpPopupForm : PopupGridLookUpEditForm
{
public MyGridLookUpPopupForm(GridLookUpEdit ownerEdit)
: base(ownerEdit) {
} protected override void OnKeyDown(KeyEventArgs e) {
if (e.KeyCode == Keys.Tab) {
this.OwnerEdit.EditValue = QueryResultValue();
this.OwnerEdit.SendKey(e);
} base.OnKeyDown(e);
}
}
}
自定义GridLookUpEdit编辑器的更多相关文章
- springmvc自定义日期编辑器
1.控制器 @Controller public class MyController { // 处理器方法 @RequestMapping(value = "/first.do" ...
- 使用 TypeScript,React,ANTLR 和 Monaco Editor 创建一个自定义 Web 编辑器(二)
译文来源 欢迎阅读如何使用 TypeScript, React, ANTLR4, Monaco Editor 创建一个自定义 Web 编辑器系列的第二章节, 在这之前建议您阅读使用 TypeScrip ...
- 我的第一个npm包:wechat-menu-editor 基于Vue的微信自定义菜单编辑器
wechat-menu-editor 微信自定义菜单编辑器 前言 在做微信公众号相关开发时,基本上会去开发的功能就是微信自定义菜单设置的功能,本着不重复造轮子的原则,于是基于Vue封装的一个微信自定义 ...
- 自定义GridControl编辑器
本文版权归博主 惊梦无痕 所有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作.SourceLink 鉴于网上的针对GridControl的一些代码比较凌乱,且功能分散,故将整理过的代码分享出来 ...
- C#如何在DataGridViewCell中自定义脚本编辑器
上一篇博文探讨了如何自定义DataGridViewColumn实现一个TreeViewColumn来在DataGridView控件中显示TreeView控件,其实我们还可以继续发挥想象,自定义其他的列 ...
- 如何自定义kindeditor编辑器的工具栏items即去除不必要的工具栏或者保留部分工具栏
kindeditor编辑器的工具栏主要是指编辑器输入框上方的那些可以操作的菜单,默认情况下编辑器是给予了所有的工具栏.针对不同的用户,不同的项目,不同的环境,可能就需要保留部分工具栏.那么我们应该如何 ...
- Unity编辑器:自定义编辑器样式——GUIStyle
通过GUIStyle,可以自定义Unity编辑器的样式. GUIStyle可以new一个全新的实例,这样,需要自己处理所有自己需要的效果. GUIStyle还可以基于已经存在的实例new一个新的实例, ...
- 【Unity】自定义编辑器窗口——拓展编辑器功能
最近学习了Unity自定义编辑器窗口,下面简单总结,方便用到时回顾. 新建一个脚本: using UnityEngine; using System.Collections; using UnityE ...
- 百度编辑器(UEditor)自定义工具栏
百度编辑器(UEditor)自定义工具栏的自定义 百度编辑器默认功能比较齐全,但是不一定是我们所需要的,有的功能可以去掉,用自己想要的就可以了,可以参考百度官方文档! 百度编辑器默认配置展示界面 如何 ...
随机推荐
- Java多线程:线程间通信之volatile与sychronized
由前文Java内存模型我们熟悉了Java的内存工作模式和线程间的交互规范,本篇从应用层面讲解Java线程间通信. Java为线程间通信提供了三个相关的关键字volatile, synchronized ...
- .NET开发微信小程序-微信支付
前台MD5加密代码 /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algor ...
- 【多线程】-ThreadPool线程池
ThreadPool介绍: Thread类是一个静态类,所有不存在实例化构造函数操作,直接可以调用其内所存在的方法. 微软官网给出的解释: 提供一个线程池,该线程池可用于执行任务.发送工作项.处理异步 ...
- Spring对象生存周期(Scope)的分析
一.Scope定义 Scope用来声明容器中管理的对象所应该处的限定场景或者说对象的存活时间,即容器在对象进入相应的Scope之前,生产并装配这些对象,在该对象不再处于这些Scope之后,容器通常会销 ...
- PAT1021:Deepest Root
1021. Deepest Root (25) 时间限制 1500 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A graph ...
- 网络Socket编程及实例
1 TCP和UDP介绍 在介绍TCP和UDP之前,有必要先介绍下网络体系结构的各个层次. 1.1 网络体系结构 协议:控制网络中信息的发送和接收.定义了通信实体之间交换报文的格式和次序,以及在报文传 ...
- vi/vim的常用快捷键
vi/vim分为 命令模式,插入模式(编辑模式),末行模式(最后一行) 模式的转换 ① 其它模式==>正常模式 按 Esc键 ②正常模式==>插入模式 按 i 在光标前插入 按 I 在行首 ...
- Vim手册
什么是 vim? Vim是从 vi 发展出来的一个文本编辑器.代码补完.编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用. 简单的来说, vi 是老式的字处理器,不过功能已经很齐全了,但是 ...
- 2017年Kali Linux更新源
终端输入: leafpad /etc/apt/sources.list 打开更新源配置文件,将下面的更新源复制到原内容的前面: #163网易 Kali源 deb http://mirrors.163. ...
- latex中长公式换行,很好的办法
今天在编辑公式时,有一个公式很长,写到一行就出去了.当时之前换行都是方程组或者在括号完之后换,都没有问题.但是今天我也换行的是在括号中间断开.这样出现问题,编辑的时候会出错误提醒.上网查了一些论坛,也 ...