手机
当前位置:查字典教程网 >编程开发 >C#教程 >DevExpress根据条件设置GridControl RepositoryItem是否可编辑
DevExpress根据条件设置GridControl RepositoryItem是否可编辑
摘要:本文实例展示了DevExpress根据条件设置GridControlRepositoryItem是否可编辑的方法。一般在C#项目的开发中,并...

本文实例展示了DevExpress根据条件设置GridControl RepositoryItem是否可编辑的方法。

一般在C#项目的开发中,并不是每个RepositoryItem都可以编辑,往往是有条件性的,需要譬如当A列等于“AA”的时候,B列才可编辑,实现起来在ShowingEditor事件中最为方便,并且加入toolTip提示显得人性化。

主要功能代码如下:

private void gvLampConfig_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) { GridView _view = sender as GridView; if (_view.FocusedColumn.Name == "colSavePowerGp1")//当列等于colSavePowerGp1 { string _type = _view.GetRowCellDisplayText(gvLampConfig.FocusedRowHandle, "OptStatusText_gp1"); if (!_type.Equals("节能"))//当列OptStatusText_gp1的列值不等于OptStatusText_gp1 { e.Cancel = true; ShowToolTip(toolTipController, "提示", "当是【调光状态】是节能模式情况,可以设置该值!"); } } } public static void ShowToolTip(ToolTipController toolTip, string title, string content) { Point _mousePoint = Control.MousePosition; toolTip.ShowHint(content, title, _mousePoint); }

代码运行效果如下:

DevExpress根据条件设置GridControl RepositoryItem是否可编辑1

为了调高代码复用性,方便后续使用,可以这样子封装一下:

/// <summary> /// 设置RepositoryItem是否可编辑 /// 说明: /// 在ShowingEditor事件中使用 /// </summary> /// <param name="view">GridView</param> /// <param name="focusedColumnName">需要设置的列名称</param> /// <param name="conditonHanlder">判断委托</param> /// <param name="toolTip">ToolTipController</param> /// <param name="title">当条件委托成立的时候提示标题</param> /// <param name="content">当条件委托成立的时候提示内容</param> /// <param name="e">CancelEventArgs</param> private void CustomShowingEditorWithToolTip(GridView view, string focusedColumnName, Func<object, bool> conditonHanlder, ToolTipController toolTip, string title, string content, CancelEventArgs e) { if (view.FocusedColumn.Name.Equals(focusedColumnName)) { if (conditonHanlder(view.GetFocusedRow())) { e.Cancel = true; Point _mousePoint = Control.MousePosition; toolTip.ShowHint(content, title, _mousePoint); } } }

代码使用如下:

private void gvLampConfig_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) { GridView _view = sender as GridView; CustomShowingEditorWithToolTip(_view, "colSavePowerGp1", arg => ((LampSelfRunCfgParamter)arg).OptStatusText_gp1 != "节能", toolTipController, "提示", "当是【调光状态】是节能模式情况,可以设置该值!", e); }

希望本文所示代码能对大家有所帮助!

【DevExpress根据条件设置GridControl RepositoryItem是否可编辑】相关文章:

C#删除文件目录或文件的解决方法

c# 类型转换

关于c#二叉树的实现

c#中判断字符串是不是数字或字母的方法

深入分析C#连接Oracle数据库的连接字符串详解

.net 一些无法catch的异常

C#实现大数字运算的实例代码

C#利用WMI操作DNS服务器(可远程操作,需要相应权限)

在C#中调用VBScript、javascript等脚本的实现代码

深入理解C# abstract和virtual关键字

精品推荐
分类导航