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

8 posts, 0 answers
  1. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 03 Aug 2011 Link to this post

    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));
                }
            }
     
        }
     
    }

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 08 Aug 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 09 Aug 2011 Link to this post

    Hi Yana,

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

  5. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 10 Aug 2011 Link to this post

    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 >>

  6. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 10 Aug 2011 Link to this post

    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...

  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 10 Aug 2011 Link to this post

    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 >>

  8. Eric
    Eric avatar
    9 posts
    Member since:
    Jun 2011

    Posted 14 Sep 2011 Link to this post

    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.
  9. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 19 Sep 2011 Link to this post

    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 >>

Back to Top
DevCraft banner