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

Calendar not updated when SelectedValue is changed in code...

7 Answers 137 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 03 Aug 2011, 01:24 PM
Hello,

I am working with the RadDateTimePicker.  I have implemented some logic in my setter such that when a user chooses a date, it will revert back to the previous Saturday.  (see GetCorrectedDate in my code) .

This seems to almost work properly - the textbox is updated appropriately and the SelectedValue is set properly but the calendar is not updated.

Try this:
1) Click the "Tuesday August 2nd 2011" button which will set the DataContext and SelectedValue to 8/2/2011 which will be changed to 7/30/2011).
2) Now open the datepicker and notice everything looks fine.  select July 26 from the picker and notice that it closes, the textbox is updated to 7/23/2011, the SelectedValue property is changed.
3) reopen the calendar and notice that July 26 is still "selected"...

<UserControl    x:Class="SilverlightApplication56.MainPage"
>
 
   <StackPanel>
 
      <Button Content="Tuesday August 2nd 2011" Click="Button_Click1" Margin="10" />
         
      <telerik:RadDatePicker x:Name="dp" SelectedValue="{Binding TheDate, Mode=TwoWay}" Margin="10" />
         
   </StackPanel>
 
</UserControl>
using System;
using System.Windows;
using System.Windows.Controls;
 
namespace SilverlightApplication56
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
 
        private void Button_Click1(object sender, RoutedEventArgs e)
        {
            this.DataContext = new SomeVM(new DateTime(2011, 08, 02, 15, 35, 57));
        }
         
    }
 
}
using System;
using System.ComponentModel;
 
namespace SilverlightApplication56
{
     
    public class SomeVM : INotifyPropertyChanged
    {
 
        public SomeVM(DateTime i)
        {
            this.TheDate = i;
        }
 
        private DateTime _TheDate = DateTime.MinValue;
        public DateTime TheDate
        {
            get
            {
                return _TheDate;
            }
            set
            {
                _TheDate = GetCorrectedDate(value);
                RaisePropertyChanged("TheDate");
            }
        }
 
        private DateTime GetCorrectedDate(DateTime dt)
        {
            DateTime resultDate = dt;
 
            while (resultDate.DayOfWeek != DayOfWeek.Saturday)
            {
                resultDate = resultDate.AddDays(-1);
            }
            return resultDate;
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null))
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
 
    }
 
}

7 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 08 Aug 2011, 01:28 PM
Hi Rob,

Could you please specify which version of the controls exactly you're using? Is it Q2 2011 official release or an older one? Thanks 

Regards,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Rob
Top achievements
Rank 1
answered on 09 Aug 2011, 01:03 PM
Hi Yana,

We are using version 2011.2.718.1040 which I believe is a hotfixed version of the Q2 2011 release...

0
Yana
Telerik team
answered on 10 Aug 2011, 01:01 PM
Hello Rob,

Thank you for the additional information, we were able to observe the erroneous behavior. I discussed it with our developers and it seems that this is an unsupported scenario. When the value of the DatePicker is updated from code like this while the Calendar is open,  the SelectedDate of the Calendar is set to the clicked item.

We're sorry for the inconvenience and hope this is not a show-stopper for you.

All the best,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Rob
Top achievements
Rank 1
answered on 10 Aug 2011, 01:24 PM
Hi Yana,

It's not a showstopper problem for us, just an annoyance really.   However, you mentioned
 "When the value of the DatePicker is updated from code like this while the Calendar is open, the SelectedDate of the Calendar is set to the clicked item."

My problem is actually when the calendar is closed.  I select the date using the calendar which closes it afterwards.  In the "set" I then update the date so the Textbox shows the correct date.  If I then go and re-open the Calendar, it's still pointing to the old date...

0
Yana
Telerik team
answered on 10 Aug 2011, 01:35 PM
Hello Rob,

I'm sorry for not explaining clearly.

I meant that the selection is made from the calendar, while the dropdown is opened. We understand the problem, just the Calendar is not supposed to update its value in this case.

Kind regards,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Eric
Top achievements
Rank 1
answered on 15 Sep 2011, 12:04 AM
Do you see this being fixed in a later release of RadControls? I'm having a similar issue, and it looks as though I'll have to use another control to get the desired effect. This is unfortunate because the datepicker tool looks so nice, and the calendar gives the user a reference while selecting a week.
0
Yana
Telerik team
answered on 19 Sep 2011, 11:55 AM
Hi Eric,

Currently we're not planning to change this behavior of the DatePicker, because it may lead to some unexpected results. We're sorry for the inconvenience.

Greetings,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
DatePicker
Asked by
Rob
Top achievements
Rank 1
Answers by
Yana
Telerik team
Rob
Top achievements
Rank 1
Eric
Top achievements
Rank 1
Share this question
or