当前位置: 编程技术>.net/c#/asp.net
DevExpress实现GridControl单元格编辑验证的方法
来源: 互联网 发布时间:2014-11-01
本文导语: 本文实例演示了DevExpress实现GridControl单元格编辑验证的方法,比较实用的功能,具体方法如下: 主要功能代码如下: /// /// 自定义单元格验证 /// /// GridView /// BaseContainerValidateEditorEventArgs /// 委托 /// 委托 /// 当验证不...
本文实例演示了DevExpress实现GridControl单元格编辑验证的方法,比较实用的功能,具体方法如下:
主要功能代码如下:
///
/// 自定义单元格验证
///
/// GridView
/// BaseContainerValidateEditorEventArgs
/// 委托
/// 委托
/// 当验证不通过对时候,错误提示信息文字
public static void CustomValidatingEditor(this GridView view, BaseContainerValidateEditorEventArgs e, Predicate fieldNameHandler, Predicate 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(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(value.ToString()), "若想设置为不修改,请输入-1即可");
}