Exemple #1
0
        protected override bool Validate()
        {
            bool         valid         = true;
            bool         ok2Validate   = true;
            IValidatable iValidatatble = ControlToValidate.Parent as IValidatable;

            if (iValidatatble != null)
            {
                ok2Validate = iValidatatble.Ok2Validate();
            }

            if (IsEnabled &&
                ControlToValidate != null &&
                ControlToValidate.Enabled &&
                ErrorProvider != null &&
                ok2Validate)
            {
                // Is valid if different than initial value,
                // which is not necessarily an empty string
                string controlValue = ControlToValidate.Text.Trim();
                string initialValue;
                if (_initialValue == null)
                {
                    initialValue = "";
                }
                else
                {
                    initialValue = _initialValue.Trim();
                }
                _isValid = (controlValue != initialValue);
                string errorMessage = "";
                if (!_isValid)
                {
                    errorMessage = _errorMessage;
                    if (_icon != null)
                    {
                        ErrorProvider.Icon = _icon;
                    }
                    valid = false;
                    if (ControlToValidate is ATMLControl)
                    {
                        ((ATMLControl)ControlToValidate).HasErrors = true;
                    }
                }
                ErrorProvider.SetError(_controlToValidate, errorMessage);
            }
            return(valid);
        }