DevExpress实现GridControl单元格编辑验证的方法
程序员文章站
2023-12-18 11:36:58
本文实例演示了devexpress实现gridcontrol单元格编辑验证的方法,比较实用的功能,具体方法如下:
主要功能代码如下:
///
本文实例演示了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即可"); }