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

Today button on Calendar Control

3 Answers 250 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Robyn
Top achievements
Rank 1
Robyn asked on 13 May 2013, 06:53 AM
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

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 May 2013, 05:54 AM
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?
0
John
Top achievements
Rank 1
answered on 22 May 2014, 10:03 PM
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


0
Stefan
Telerik team
answered on 23 May 2014, 06:48 AM
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.
 
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Robyn
Top achievements
Rank 1
Answers by
Stefan
Telerik team
John
Top achievements
Rank 1
Share this question
or