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

Auto close when time selected?

5 Answers 539 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
madladuk
Top achievements
Rank 2
madladuk asked on 09 Sep 2010, 03:34 PM
Hi.

When you select a time from the selection box is possible to auto-close? At the moment you have to select the icon again for the calendar to be removed.


Thanks P

5 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 09 Sep 2010, 03:48 PM
Hi Paul,

 Currently the DateTimePicker control closes its popup when value is selected with the mouse only if it its InputMode is DatePicker or TimePicker. If you want to change this behavior you need to handle the DateTimeSelectedWithMouseEvent routed event of the RadDateTimePicker control (it is not exposed as a CLR event, but you can still handle it). Here is our current code that closes the DateTimePicker drop-down. What you will need to do is similar:

EventManager.RegisterClassHandler(typeof(RadDateTimePicker), RadDateTimePicker.DateTimeSelectedWithMouseEvent, new RoutedEventHandler(OnDateTimeSelectedWithMouse));
 
 
private static void OnDateTimeSelectedWithMouse(object sender, RoutedEventArgs args)
{
    var picker = sender as RadDateTimePicker;
 
    // If the picker is not a DateTimePicker and the drop-down is opened than close it.
    if (picker != null && picker.InputMode != InputMode.DateTimePicker && picker.IsDropDownOpen)
    {
        picker.IsDropDownOpen = false;
    }
}

Best wishes,
Miroslav Nedyalkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Simon
Top achievements
Rank 1
answered on 21 Feb 2012, 11:31 PM
Hi Miroslav,

We have a DateTimePicker where the inputmode is DateTimePicker. However we only want to close the dropdown when the Time is selected. You solution does not cater for this.

Can you propose a way to do this using your DateTimeSelectedWithMouseEvent. We just need to test that the Time portion of the control has been selected.

Thanks
Simon
0
Miroslav Nedyalkov
Telerik team
answered on 22 Feb 2012, 12:37 PM
Hello,

What I would suggest you is to change the code in the event handler with the following:

var picker = sender as RadDateTimePicker;
 
// If the picker is not a DateTimePicker and the drop-down is opened than close it.
if (picker != null && picker.IsDropDownOpen && ((RadRoutedEventArgs)args).Source is RadClock)
{
    picker.IsDropDownOpen = false;
}

The idea is to identify which control was actually clicked - the calendar or the clock and if the clock is clicked, than close the drop down.

Hope this helps.

Regards,
Miroslav Nedyalkov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
1
Talal
Top achievements
Rank 1
answered on 31 Jan 2013, 12:12 PM


I succeeded with auto close in case of time input section selected. Using this

EventManager.RegisterClassHandler(
typeof(RadDateTimePicker), RadDateTimePicker.DateTimeSelectedWithMouseEvent, new RoutedEventHandler(OnDateTimeSelectedWithMouse));
private static void OnDateTimeSelectedWithMouse(object sender, RoutedEventArgs args)
{
var picker = sender as RadDateTimePicker;
// If the picker is a DateTimePicker and the drop-down is opened than close it if mouse down on time selection.
if (picker != null && picker.InputMode == InputMode.DateTimePicker && picker.IsDropDownOpen &&(args).OriginalSource is RadClock)
{
picker.IsDropDownOpen = false;
}
}
0
Ad
Top achievements
Rank 2
answered on 09 Mar 2015, 12:11 PM
I implemented a custom 'Today' button using my own style, and I had the same problem: the DateTimePicker does not close automatically after pressing 'Today' (while this works perfect when clicking any Date in the DateTimePicker).
Now I'm using the fix described above, and it works like a charm:

        private void DatePicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ViewModel.CurrentPeriodChangeInfo.CurrentDate = DateTimePicker.DisplayDate;
            DateTimePicker.IsDropDownOpen = false;
        }
Tags
DateTimePicker
Asked by
madladuk
Top achievements
Rank 2
Answers by
Miroslav Nedyalkov
Telerik team
Simon
Top achievements
Rank 1
Talal
Top achievements
Rank 1
Ad
Top achievements
Rank 2
Share this question
or