This is a migrated thread and some comments may be shown as answers.

Show empty date value on load

3 Answers 373 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Joe Bohen
Top achievements
Rank 1
Joe Bohen asked on 03 Nov 2015, 06:12 PM

Hi,

 

I have a RadDateTimePicker which is databound to a class object when my form loads I want to display and empty value in order that the watermark content is displayed. I also want to display a date range when the date time picker is selected and in order to do this I am setting the display range values when the main window is loaded. My problem is that I am seeing the default null value  01/01/0001 00:00:00!  How do I achieve this behavior 

 

<telerik:RadDateTimePicker x:Name="DeldateTime" Width="160" TimeInterval="0:30:0" DateTimeWatermarkContent="Delivery Date\Time" SelectedValue="{Binding dtDeliverDate, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Height="26" VerticalAlignment="Bottom" ToolTip="Delivery date - Select both Day and Time values!" TabIndex="4" IsTabStop="True"  />

Date range set on loaded event

Me.DeldateTime.SelectableDateStart = DateTime.Now.AddMonths(-3)
Me.DeldateTime.SelectableDateEnd = DateTime.Now.AddMonths(3)
Me.DeldateTime.DisplayDate = DateTime.Now

Property

Public Property dtDeliverDate() As DateTime
        Get
            Return Me.m_dtDeliverDate
        End Get
        Set(value As DateTime)
            Me.m_dtDeliverDate = value
            If IsDate(m_dtDeliverDate) Then
                Me.m_szDeliveryTime = Format(m_dtDeliverDate, "HH:mm")
            End If
            Me.SendPropertyChanged("dtDeliverDate")
        End Set
    End Property​

 

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 05 Nov 2015, 02:56 PM
Hi Joe,

The observed by you behavior of RadDateTimePicker is caused by the SelectedValue property. Actually, you are binding it to a property of type DateTime and its initial and default value is "01/01/0001 00:00:00". 

However, the SelectedValue property is actually of type DateTime?. So, by changing the type of the property to be DateTime? the watermark should be displayed as expected:
Private m_dtDeliverDate As DateTime?
 
Public Property DtDeliverDate() As DateTime?
    Get
        Return Me.m_dtDeliverDate
    End Get
 
    Set(ByVal value As DateTime?)
        If Not Me.m_dtDeliverDate.Equals(value) Then
            Me.m_dtDeliverDate = value
            Me.OnPropertyChanged(Function() Me.m_dtDeliverDate)
        End If
    End Set
End Property

Hope this helps.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Joe Bohen
Top achievements
Rank 1
answered on 08 Nov 2015, 11:37 AM

Hi Nasko,

Thank you for your reply, but I am a little confused by your suggestion that I set the value to a ​DateTime I was under the impression that I was already doing that!  Can you provide me with an example based on the information provided please.

Regards,

Joe

0
Nasko
Telerik team
answered on 09 Nov 2015, 11:04 AM
Hello Joe,

Attached you could find a sample project that demonstrates the described in my previous response approach? Could you please check it and let me know if I didn't miss something and that is the behavior you are looking for?

If there is something missed could you please, modify the sample in order to reproduce your issue and send it back to us - thus we could be able to provide you with a prompt solution?

We are looking forward to hearing from you.  

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DateTimePicker
Asked by
Joe Bohen
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Joe Bohen
Top achievements
Rank 1
Share this question
or