0
 public class Person
    {
        private string firstName;
        public string FirstName
        {
            get { return firstName; }
            set
            {
                if (string.IsNullOrEmpty(value))
                    throw new ArgumentNullException("FirstName cannot be null.");

                firstName = value;
            }
        }

        private string lastName;
        public string LastName
        {
            get { return lastName; }
            set
            {
                if (string.IsNullOrEmpty(value))
                    throw new ArgumentNullException("LastName cannot be null.");

                lastName = value;

            }
        }
        public int Age { get; set; }
    }

Person 字段(文本框)和 errorProvider 绑定到 personBindingSource。

有没有办法引发脏事件,以便 errorProvider 将捕获并显示用户是否输入了 FirstName。目前,它仅在您在字段中键入一些字符时才有效,然后删除它们,错误提供程序将显示。

即使我打电话

personBindingSource.EndEdit();

如果我从未输入过名字文本框,它永远不会触发,有什么解决方法吗?

问候

_埃里克

4

1 回答 1

1

set FirstName = "",在构造函数中或绑定对象之前的任何其他位置。错误将立即可见。

于 2011-05-06T20:50:06.920 回答