Write Null/Nothing value with Databinding

Posted by clawson on Stack Overflow See other posts from Stack Overflow or by clawson
Published on 2010-05-19T08:38:13Z Indexed on 2010/05/19 8:40 UTC
Read the original article Hit count: 298

Filed under:
|

I have extended a MaskedTextBox component to add some functionality. The text property of the extended MaskedTextBox is bound to a DateTime? property and the format of binding is set to a time format of "HH:mm:ss" (i.e. 24hr time). So that this masked text box will capture the display a time.

The extra functionality I have added is to make the component readonly unless the component is double clicked or the enter button is pressed (the back color of the control helps to inform the users if the component is locked/readonly or not). When the enter button is pressed I also suspend the bindings so that bound data is updated the users input won't be lost. The information is then written back to the value and databindings resumed when the user presses the enter key again.

This all works fine up to here, with values written and displayed as would be expected.

However, I also want to write the null or nothing value to the DateTime? property if the user hasn't entered any text (or invalid text but let's just stick with no text) when enter key is pressed to submit the new value.

Unlike with other valid entries in the MaskedTextBox, with no text entered when i execute:

        Me.DataBindings("Text").WriteValue()

(when 'locking' the MaskedTextBox) it then branches to the bound properties Get method as I step into each line of code in the debugger (as opposed to the Set method with other valid entries)

How can I write this null/nothing/"" value to the DateTime? property when no text "" is entered into the MaskedTextBox?

Thanks for the help!

© Stack Overflow or respective owner

Related posts about .NET

Related posts about databinding