Devexpress GridControl数据验证的方法

向GridView里增加两个事件

 1 private void gdvStruct_ValidatingEditor(object sender, BaseContainerValidateEditorEventArgs e)
 2 {
 3 ColumnView view = sender as ColumnView;
 4 GridColumn column = (e as EditFormValidateEditorEventArgs)?.Column ?? view.FocusedColumn;
 5 if (column.FieldName != "StructName") return;
 6 string value = e.Value.ToString();
 7 e.Valid = Regex.IsMatch(value, @"^[\u4E00-\u9FA5a-zA-Z0-9_.]+$");
 8 }
 9 
10 private void gdvStruct_InvalidValueException(object sender, InvalidValueExceptionEventArgs e)
11 {
12 ColumnView view = sender as ColumnView;
13 if (view == null) return;
14 e.ExceptionMode = ExceptionMode.DisplayError;
15 e.WindowCaption = "格式错误";
16 e.ErrorText = "只允许英文字母、数字、汉字和.";
17 view.HideEditor();
18 }

Devexpress GridControl数据验证的方法

上一篇:DevExpress表格GridControl控件属性设置总结


下一篇:WPF material UI 的使用