BindingSource, EndEdit, & ErrorProvider raise event on unchanged fields

1.1k Views Asked by At
 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; }
    }

The Person fields(textboxes) & errorProvider are bound to personBindingSource.

Is there a way to raise a dirty event so the errorProvider will catch and show if the user did not enter a FirstName. Currently it only works if you tab into the field type some characters, then delete them the error provider will display.

Even though I call

personBindingSource.EndEdit();

if I never typed in the firstName textbox, it will never fire, any workarounds?

Regards

_Eric

1

There are 1 best solutions below

0
On

set FirstName = "", either in the constructor or anywhere else before the object is bound. The error will be visible immediately.