方法①:使用 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;
            }
        }
    }
View Code

相关文章:

  • 2021-08-03
  • 2022-12-23
  • 2021-05-13
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-18
  • 2021-09-14
  • 2021-07-18
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
相关资源
相似解决方案