Today button on Calendar Control

4 posts, 0 answers
  1. Robyn
    Robyn avatar
    17 posts
    Member since:
    Aug 2011

    Posted 13 May 2013 Link to this post

    G'day,

    I am using a Telerik WinForms Calendar control, with the footer visible so that I can use the Today button.

    Unfortunately, when I click the Today button the control only 'shows' today. FOr example, if I had a date in November 2014 selected the control would only move the visible month to todays month (April 2013). 

    My desired behaviour is for the calendar to move the display and ALSO select the date (triggering all the usual SelectedDateChanged events).

    Do I need to handle the TodayButton click event? How do I do this? Is this possible in any way?

    EDIT: It looks like it adds today's date to the selected dates, instead of replacing the selecteddate with todays date. Is this the designed behaviour?

    Kind Regards,
    Connect Direct Team
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 16 May 2013 Link to this post

    Hello Robyn,

    Thank you for writing.

    Clicking the Today button in the footer of RadCalendar will just set the focused date of the control and till not select it. If you want to select the date as well you have to do it in the Click event of the Today's button:
    radCalendar1.TodayButton.Click += TodayButton_Click;
     
     void TodayButton_Click(object sender, EventArgs e)
     {
         radCalendar1.SelectedDate = radCalendar1.FocusedDate;
     }

    I hope that the provided information addresses your question.

    Greetings,
    Stefan
    the Telerik team
    RadChart for WinForms is obsolete. Now what?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. John
    John avatar
    21 posts
    Member since:
    Sep 2013

    Posted 22 May 2014 in reply to Stefan Link to this post

    Hi, 
    I'm having some issues with the Today and Clear buttons on the RadCalendar control of RadDateTimePicker.  I want the behavior to be just like the Calendar in the GridViewDateTimeColumn; eg, selecting the buttons changes the text of the control (to today or blank) and the Calendar then goes away.  But in RadDatetimePicker
    1) the buttons do not show up by default.
    2) If I make the buttons visible Today only selects the date but does not change the text. and clear does nothing. 
    3) If I handle the events (as shown in the previous post, above) it sets the text but does not hide the Calendar.

    Furthermore, I am adding the RadDateTimePicker controls programmatically and there may be more than one on a form, so in the handler it is difficult to determine which RadDateTimePicker invoked the event (sender is a RadButton, not a  RadDatetimepicker or RadCalendar).  Is ActiveControl property the best way to do this?

    Thanks for your help,

    John


  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 23 May 2014 Link to this post

    Hello John,

    Thank you for writing.

    Since you mention you will have multiple instances of this control and you want this behavior in all of them, it will be best to create a descendant of the control where you can introduce the desired modificatons. Here is a sample implementation:
    class MyPicker : RadDateTimePicker
    {
        public MyPicker()
        {
            RadDateTimePickerCalendar calendarBehavior = this.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
            RadCalendar calendar = calendarBehavior.Calendar as RadCalendar;
            calendar.ShowFooter = true;
            calendar.ClearButton.Click += ClearButton_Click;
            calendar.TodayButton.Click += TodayButton_Click;
        }
     
        void TodayButton_Click(object sender, EventArgs e)
        {
            this.Value = DateTime.Now.Date;
            RadDateTimePickerCalendar calendarBehavior = this.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
            calendarBehavior.PopupControl.ClosePopup(RadPopupCloseReason.CloseCalled);
        }
     
        void ClearButton_Click(object sender, EventArgs e)
        {
            this.SetToNullValue();
            RadDateTimePickerCalendar calendarBehavior = this.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
            calendarBehavior.PopupControl.ClosePopup(RadPopupCloseReason.CloseCalled);
        }
     
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadDateTimePicker).FullName;
            }
        }
    }

    I hope that you find this information useful.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top