public bool UpdateErrorProviderTextForProperty(string errorMessage, string propertyName) { if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException("propertyName"); } if (string.IsNullOrEmpty(errorMessage)) { throw new ArgumentNullException("errorMessage"); } bool result = false; Binding bindingGivenPropertyName = this.GetBindingGivenPropertyName(propertyName); if (bindingGivenPropertyName != null) { ExchangeErrorProvider exchangeErrorProvider = this.enabledBindingSources[(BindingSource)bindingGivenPropertyName.DataSource]; StringBuilder stringBuilder = new StringBuilder(exchangeErrorProvider.GetError(bindingGivenPropertyName.Control)); if (stringBuilder.Length > 0) { stringBuilder.AppendLine(); } stringBuilder.Append(errorMessage); Control errorProviderAnchor = InputValidationProvider.GetErrorProviderAnchor(bindingGivenPropertyName.Control); exchangeErrorProvider.SetError(errorProviderAnchor, stringBuilder.ToString()); result = true; } return(result); }
private void Control_EnabledChanged(object sender, EventArgs e) { Control control = (Control)sender; if (!control.Enabled) { foreach (object obj in control.DataBindings) { Binding binding = (Binding)obj; BindingSource bindingSource = binding.DataSource as BindingSource; if (bindingSource != null) { ExchangeErrorProvider errorProvider = this.GetErrorProvider(bindingSource); if (errorProvider != null) { Control errorProviderAnchor = InputValidationProvider.GetErrorProviderAnchor(control); errorProvider.SetError(errorProviderAnchor, string.Empty); } } } } }