Auto close when time selected?

6 posts, 0 answers
  1. madladuk
    madladuk avatar
    126 posts
    Member since:
    Dec 2009

    Posted 09 Sep 2010 Link to this post

    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
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 09 Sep 2010 Link to this post

    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
  3. DevCraft banner
  4. Simon
    Simon avatar
    47 posts
    Member since:
    May 2008

    Posted 21 Feb 2012 Link to this post

    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
  5. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 22 Feb 2012 Link to this post

    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 >>
  6. Talal
    Talal avatar
    1 posts
    Member since:
    Jan 2013

    Posted 31 Jan 2013 Link to this post



    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;
    }
    }
  7. Ad
    Ad avatar
    3 posts
    Member since:
    Nov 2014

    Posted 09 Mar 2015 in reply to Talal Link to this post

    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;
            }
Back to Top
DevCraft banner