方法①:使用 ValidatingEditor 事件(一般用于对整个GridView内的文本框进行数据验证)
当单元格输入格式错误时,直接在该行下方提示,代码如下:
using System.Text.RegularExpressions; //注意添加引用 private void gridView1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e) { if (gridView1.FocusedColumn == colcount) //设置校验列 { bool result = false; Regex regex = new Regex(@"^\+?\d+$"); result = regex.IsMatch(e.Value.ToString()); if (!result) { e.ErrorText = "请输入一个正整数"; e.Valid = false; return; } } }