I am trying to databind a smartdate (actually the Text property of a smartdate) to a cell in a datagridview.
Now I know I can write some validation methods to check that, for exmaple, that the date is greater than today, and I can use the errorprovider to display a nice error message.
However, I seem lost as to how I can validate that the text typed in as being a date.
i.e. If the person types in "ASDF" for the date, I would like to show a validation error message just as if they typed in "1/1/1900" for a date that must be in the future.
The only thing I can think of is to do some work arounds, for example:
1) check the text to make sure its a date
2) if not a valid date, don't set the SmartDate Text property and instead store the "bad" text in a private variable
3) Call the propertychanged
4) check the "bad" text variable and raise a validation error.
I'm thinking there should be a better way to do this... anyone know how to validate that the text for a smartdate and tap into the errorprovider/validation events?
cmay,
As fas as I know SmartDate already does this check for you when you set the Text property.
Dim sd as new csla.SmartDate
sd.Text = "ASDF"
will result in an exception...
An unhandled exception of type 'System.ArgumentException' occurred in Csla.dll
Additional information: String value can not be converted to a date
...and the SmartDate object will keep the value it had before...
HTH,
Jurjen.
Well it does throw that error, but that exception doesn't work with errorprovidor.
I can catch that error and display my own msgbox to the user, but there is already this built in method for checking (validating) the values using the CSLA Vadation Rules. I am trying to tap into that so I can get the nice inline error icons and tooltips and what not.
Copyright (c) Marimer LLC