Textbox bound to a date wont let me Blank it out

johncassell

Well-known member
Joined
Jun 10, 2007
Messages
120
Location
Redcar, England
Programming Experience
Beginner
Hi There,

I have a textbox on my form which is bound to a date field in my table.

I am trying to enable it so that a user can simply delete what is in there and move on but if it is blank it makes you stay in the box.

Can anyone help with this pls?

Thanks

John
 
Does your date column allow nulls? If not then a blank value doesn't make any sense. If it does then you have to make sure that the NullValue property of your Binding is equal to an empty string, so entering an empty string into the TextBox will push a null value to the bound record.
 
Hi There, thanks for the reply. My date column DOES allow nulls so that is ok. However, I am confused as to what you mean by:

If it does then you have to make sure that the NullValue property of your Binding is equal to an empty string

I don't really know where to look. Can you advise pls.

Thanks again

John
 
I've clicked on my textbox, gone into the databindings advanced properties (see screen shot) and put "" in the nullvalue. But this hasn't made any difference..
 

Attachments

  • databind.JPG
    databind.JPG
    55.6 KB · Views: 47
I think you'll find that what you've done there is say that a string containing two double quotes, NOT an empty string, represents a null value. The default value for the NullValue property is Nothing. It may be that by setting it to anything at all in that dialogue, pressing OK, then opening the dialogue again and clearing it will set it to an empty string. I'm not sure of that and it may simply set it back to Nothing again. If that's the case then you would have to set the property in code:
VB.NET:
myTextBox.DataBindings("Text").NullValue = String.Empty
 
thanks very much for that.

I found the line which handles this and where I have now put 'String.Empty' it used to say 'Nothing'

VB.NET:
Me.Complete_DateFake.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.WS_JobsBindingSource, "Complete_Date",
 True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, String.Empty, "d"))

thanks again

John
 
Back
Top