当前位置: 移动技术网 > IT编程>开发语言>c# > DevExpress根据条件设置GridControl RepositoryItem是否可编辑

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

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例展示了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);
}

代码运行效果如下:

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

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

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网