DevExpress完成GridControl單位格編纂驗證的辦法。本站提示廣大學習愛好者:(DevExpress完成GridControl單位格編纂驗證的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是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便可"); }