SmartDate - I want textbox to be empty

SmartDate - I want textbox to be empty

Old forum URL: forums.lhotka.net/forums/t/10263.aspx


ksavoie posted on Thursday, April 14, 2011

Hi

I'm at the end of my options with the SmartDate.

This is my code.

Private _contrSdtDt As SmartDate = New SmartDate(True)

Public

 Property ContrSdtDt() As DateTime
Get
     CanReadProperty("ContrSdtDt", True)
     Return _contrSdtDt.Date
End Get

 

Set(ByVal value As DateTime)
      CanWriteProperty("ContrSdtDt", True)
      If Not _contrSdtDt.Equals(value) Then
           _contrSdtDt.Date = value
           PropertyHasChanged("ContrSdtDt")
      End If
End Set
End Property

In my textbox, when creating a new record, I keep getting the "0001-01-01" value, because my date is empty, but that's not what I want.  I actually want an empty string, so an empty textbox.  I'm using a mask "9999-99-99" for that specific textbox in my window form.  And I set the DataBindings.text to my ContrSdtDt.

Can anybody help me on how to get my empty value show up in my textbox in window form?

Thanks

 

danielmartind replied on Thursday, April 14, 2011

You need your property to be a string and return the text portion of the SmartDate.

ksavoie replied on Tuesday, April 19, 2011

I already have a string property.  But is there another way of doing this by using the Date property?

Thanks

sergeyb replied on Tuesday, April 19, 2011

You can try to change your property to return .ToNullableDateTime() function, although this works much better bound to calendar control, rather than textbox.

RockfordLhotka replied on Tuesday, April 19, 2011

SmartDate is designed specifically to support the scenario where you have a string property, with a SmartDate backing field. The SmartDate type understands the concept of an "empty" value, and when it converts to a string it returns string.Empty if the SmartDate value is empty.

There is no other recommended scenario for using SmartDate.

If you just want a nullable DateTime, then use DateTime? as your property type, and deal with the null value issues in the UI itself. As Sergey says, you'll probably have better luck with a control that is smarter than a TextBox.

Copyright (c) Marimer LLC