views:

390

answers:

1

I have a MaskedTextBox that has the mask 00/00/\2\000 (restricting input to XX/XX/20XX) and DateTime values with a single digit month or day recently started displaying incorrectly. The MaskedTextBox.Text property is bound to BindingSource.SomeProperty (of type DateTime.)

I know that at some level of data-binding the ToString method is being invoked, and I expect the call is not padding month/day with zeroes.

I tried setting the advanced data-binding properties to set a DateTime format type on the MaskedTextBox.Text property, but this doesn't help.

How can I apply a format string (eg. ToString("MMddyyyy")) when converting the DateTime object to a string, before the value is bound to the Text property?

+1  A: 

You can use the binding's Parse and Format events to do the conversion yourself, as seen in this answer

Stuart Dunkeld
Thanks, that did it. Yet I can't help but wonder what changed to cause this in the first place. Are there any designer settings that would affect this? (VS2005)
Rob
The IncludePrompt and IncludeLiterals properties would be a good place to start.
Stuart Dunkeld