资源下载 - 从此开始!

下载我_精品源码软件教程资源网

您的位置:主页 > 网络编程 > 正文

DevExpress实现GridControl单元格编辑验证的方法

2018-12-01 17:39 来源:互联网 编辑:admin

本文实例演示了DevExpress实现GridControl单元格编辑验证的方法,比较实用的功能,具体方法如下:

主要功能代码如下:

/// <summary>
/// 自定义单元格验证
/// </summary>
/// <param name="view">GridView</param>
/// <param name="e">BaseContainerValidateEditorEventArgs</param>
/// <param name="fieldNameHandler">委托</param>
/// <param name="errorHanlder">委托</param>
/// <param name="errorText">当验证不通过对时候,错误提示信息文字</param>
public static void CustomValidatingEditor(this GridView view, BaseContainerValidateEditorEventArgs e, Predicate<string> fieldNameHandler, Predicate<object> errorHanlder, string errorText)
{
  /*说明
   *在ValidatingEditor事件使用
   *eg:
   *string[] workType = new string[4] { "-1", "关闭但不删除", "启用", "删除" };
   *void gvLampConfig_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
   *{
   * GridView _view = sender as GridView;
   * _view.CustomValidatingEditor(e, fieldName => fieldName.Equals("TLampWorkStatus"), value => !workType.Contains<string>(value.ToString()), "若想设置为不修改,请输入-1即可");
   * }
   */
  if (fieldNameHandler(view.FocusedColumn.FieldName))
  {
 if (errorHanlder(e.Value))
 {
   e.Valid = false;
   e.ErrorText = errorText;
 }
  }
}

代码使用方法如下:

string[] workType = new string[4] { "-1", "关闭但不删除", "启用", "删除" };
void gvLampConfig_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
{
  GridView _view = sender as GridView;
  _view.CustomValidatingEditor(e, fieldName => fieldName.Equals("TLampWorkStatus"), value => !workType.Contains<string>(value.ToString()), "若想设置为不修改,请输入-1即可");
}

打赏一下,我们会为大家提供更多优质资源!

相关文章,95%的人会看!{有内幕、有真相...}

看过本文的人还看过

关闭

微信扫一扫

站长微信账号