A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

这篇文章主要介绍了DevExpress根据条件设置GridControl RepositoryItem是否可编辑,需要的朋友可以参考下
本文实例展示了DevExpress根据条件设置GridControl RepositoryItem是否可编辑的方法。
一般在C#项目的开发中,并不是每个RepositoryItem都可以编辑,往往是有条件性的,需要譬如当A列等于“AA”的时候,B列才可编辑,实现起来在ShowingEditor事件中最为方便,并且加入toolTip提示显得人性化。
主要功能代码如下:
  1. private void gvLampConfig_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
  2. {
  3. GridView _view = sender as GridView;
  4. if (_view.FocusedColumn.Name == "colSavePowerGp1")//当列等于colSavePowerGp1
  5. {
  6. string _type = _view.GetRowCellDisplayText(gvLampConfig.FocusedRowHandle, "OptStatusText_gp1");
  7. if (!_type.Equals("节能"))//当列OptStatusText_gp1的列值不等于OptStatusText_gp1
  8. {
  9. e.Cancel = true;
  10. ShowToolTip(toolTipController, "提示", "当是【调光状态】是节能模式情况,可以设置该值!");
  11. }
  12. }
  13. }
  14. public static void ShowToolTip(ToolTipController toolTip, string title, string content)
  15. {
  16. Point _mousePoint = Control.MousePosition;
  17. toolTip.ShowHint(content, title, _mousePoint);
  18. }
复制代码

代码运行效果如下: 为了调高代码复用性,方便后续使用,可以这样子封装一下:
  1. /// <summary>
  2. /// 设置RepositoryItem是否可编辑
  3. /// 说明:
  4. /// 在ShowingEditor事件中使用
  5. /// </summary>
  6. /// <param name="view">GridView</param>
  7. /// <param name="focusedColumnName">需要设置的列名称</param>
  8. /// <param name="conditonHanlder">判断委托</param>
  9. /// <param name="toolTip">ToolTipController</param>
  10. /// <param name="title">当条件委托成立的时候提示标题</param>
  11. /// <param name="content">当条件委托成立的时候提示内容</param>
  12. /// <param name="e">CancelEventArgs</param>
  13. private void CustomShowingEditorWithToolTip(GridView view, string focusedColumnName, Func<object, bool> conditonHanlder, ToolTipController toolTip, string title, string content, CancelEventArgs e)
  14. {
  15. if (view.FocusedColumn.Name.Equals(focusedColumnName))
  16. {
  17. if (conditonHanlder(view.GetFocusedRow()))
  18. {
  19. e.Cancel = true;
  20. Point _mousePoint = Control.MousePosition;
  21. toolTip.ShowHint(content, title, _mousePoint);
  22. }
  23. }
  24. }
复制代码

代码使用如下:
  1. private void gvLampConfig_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
  2. {
  3. GridView _view = sender as GridView;
  4. CustomShowingEditorWithToolTip(_view, "colSavePowerGp1", arg => ((LampSelfRunCfgParamter)arg).OptStatusText_gp1 != "节能", toolTipController, "提示", "当是【调光状态】是节能模式情况,可以设置该值!", e);
  5. }
复制代码


1 个回复

倒序浏览
学习了!!!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马