0

I have a Form that has multiple controls.

Using a BindingSource, I bound the properties of MyClass to the controls.

The properties have custom ValidationAttributes, which override both IsValid-Methods:

IsValid(object value);
IsValid(object value, ValidationContext validationContext);

When I input something into the controls, the properties are validated correctly, but with my custom ValidationAttributes, its only validated via the IsValid(object value)-Method. Is it possible to force the Validation to run through IsValid(object value, ValidationContext validationContext) instead?

Can someone explain that behaviour?

I do realize that it would run through IsValid(object value, ValidationContext validationContext) if I used the Validator class, but I don't want the validation to be handled automatically by the form/databinding.

halfer
  • 19,824
  • 17
  • 99
  • 186
Benjamin Basmaci
  • 2,247
  • 2
  • 25
  • 46

1 Answers1

0

Found the solution in this Question here: How to create a custom validation attribute?

Ryans comment to the chosen answer (Jun 29) explains it. All I have to do is to add this:

public override bool RequiresValidationContext { get { return true; } }

Now IsValid(object, ValidationContext) is always called.

Benjamin Basmaci
  • 2,247
  • 2
  • 25
  • 46