码迷,mamicode.com
首页 > 其他好文 > 详细

[DevExpress]GridControl单元格编辑验证

时间:2014-07-01 19:49:27      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:style   color   使用   width   os   html   

关键代码:

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

[DevExpress]GridControl单元格编辑验证,布布扣,bubuko.com

[DevExpress]GridControl单元格编辑验证

标签:style   color   使用   width   os   html   

原文地址:http://www.cnblogs.com/Yan-Zhiwei/p/3816974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!