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

Clear Displayed Date and Update Source

7 Answers 305 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 17 Mar 2014, 05:40 AM
I am using a DatePicker as follows;

<telerik:RadDatePicker Name="dtpPublished"
    Margin="2"  
    Grid.Row="2"
    Grid.Column="1"
    HorizontalAlignment="Left"
    HorizontalContentAlignment="Left"
    VerticalAlignment="Center"
    MinWidth="500"
    MaxWidth="500"
    DateTimeWatermarkContent="Leave blank or enter the date this Scenario was published"
    SelectedDate="{Binding Path=PublishedDt, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
</telerik:RadDatePicker>

In the code behind I am setting the Culture and date format as follows;

With dtpPublished
    .Culture = New System.Globalization.CultureInfo("en-AU")
    .Culture.DateTimeFormat.ShortDatePattern = "d-MM-yyyy"
    .Culture.DateTimeFormat.ShortTimePattern = "hh:mm"
 
    .Culture.DateTimeFormat.LongDatePattern = "ddd, d MMM yyyy"
    .Culture.DateTimeFormat.LongTimePattern = "h:mm:ss tt"
 
    .DisplayFormat = Telerik.Windows.Controls.DateTimePickerFormat.Long
End With

My problem is if I clear the displayed date by pressing delete when the date text is highlighted I want the control to update the source as if a date wasn't entered.  Effectively it should set the source to Nothing or to Date.MinValue.  Even after I Tab off the control the source isn't updated?

Preferably the control should display a blank entry rather than "1/01/0001" as the date.

7 Answers, 1 is accepted

Sort by
0
Raymond
Top achievements
Rank 1
answered on 18 Mar 2014, 02:25 AM
Anyone have any suggestions?
0
Kalin
Telerik team
answered on 18 Mar 2014, 04:30 PM
Hi Raymond,

The SelectedDate property of the DatePicker is of type nullable DateTime (DateTime?). So it should be bound to a nullable DateTime property in the ViewModel. Please check whether the PublishedDt is of the correct type as if so the PropertyChanged event should be raised when the selection of the DatePicker has been cleared.

Hope this helps.

Regards,
Kalin
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Raymond
Top achievements
Rank 1
answered on 18 Mar 2014, 11:49 PM
Hi Kalin,

Thanks for getting back to me.

I changed the PublishedDt property in my class to Date? and DateTime? and in both the cases the DateTimePicker does not display the date when selected from the calendar.  

I can however enter the date from the keyboard and it raises a selection changed event.

The attached files illustrate;
1) The DTP before a selection is made from the calendar,
2) Selecting "6 Mar 2014" from the calendar,
3) The DTP after the date is selected,
4) Manually entering a date with the "Culture" code removed, and
5) Manually entering a date with the "Culture" code.

I also just noted that if I enter the date manually then select the a date from the calendar it does not update the original date entered.

I also tried commenting out the "Culture" code in case that was causing a problem.
0
Raymond
Top achievements
Rank 1
answered on 18 Mar 2014, 11:51 PM
0
Accepted
Kalin
Telerik team
answered on 19 Mar 2014, 08:50 AM
Hi Raymond,

We are not able to reproduce the described issue. Could you please share some more detailed information about the exact scenario as well as the version of the controls you are using? However if you are able to isolate the issue in a sample project and send it to us that would be really helpful.

I'm looking forward to hearing from you.

Regards,
Kalin
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Raymond
Top achievements
Rank 1
answered on 19 Mar 2014, 10:24 PM
Hi Kalin,

The problem turned out to be in my code.  The property was comparing the updated value with the backing variable which was nothing so the test failed.  After modifying the code to compare null values everything was OK.

Thanks for your help.
0
Kalin
Telerik team
answered on 20 Mar 2014, 07:45 AM
Hello Raymond,

We are glad you have managed to resolve the issue.

If you have any other questions let us know.

Regards,
Kalin
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
DatePicker
Asked by
Raymond
Top achievements
Rank 1
Answers by
Raymond
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or