.netwinformsenterprise-libraryvalidation-application-bl

.NET WinForms and the enterprise library validation application block


I have a TextBox whose value is passed to an int property in an object after being parsed to an int.

When I use a ValidationProvider this conversion step is ignored when validating and I get an error telling me that I cannot save the string to an int32.

I can fix this by creating a string property in my object that acts as a bridge between the textbox value in the form and the int value in my business object but I dislike this approach because it would require changing my domain objects to please the validation layer.

How can I validate a textbox that stores its value to an int after a conversion without creating a bridge property in the domain object?


Solution

  • I found an solution.

    The string to int conversion is made automatically but it fails if the textbox is left blank.

    I used the ValueConvert handler of the ValidationProvider to fix this but I am convinced that this is a bug of some sort.

    EDIT: The ValueConvert event won't fire unless there is a Validator in the property. Use [ObjectValidator] as a dummy to fire the ValueConvert event when input conversions are expected.