DateTime Control issue

Posted by: mayur.purandare on 13 December 2020, 4:52 pm EST

    • Post Options:
    • Link

    Posted 13 December 2020, 4:52 pm EST

    I am using DateTime control in our application.

    Time control can be changed by using key operation (Up-down keys ↑ / ↓). whereas the date can not be changed using Up down keys.

    To maintain consistency in these two controls I want to change the Date also using Up down keys.

    Is it possible to achieve this behavior?

  • Posted 13 December 2020, 11:21 pm EST

    Hi Mayur,

    Generally, it is not expected to use the Up/Down keys for navigating dates in a DatePicker. Therefore, you have to use the C1MaskedTextBox’s (present in C1DatePicker template) PreviewKeyDown event to handle the Up/down keys.

    For example, you can increment/decrement the date by 1 day using Up/Down keys as follows:

    
    private void MaskedTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
             if ((e.Key == Key.Up || e.Key == Key.Down) && datePicker.SelectedDate.HasValue)
             {
                  e.Handled = true;
                  switch (e.Key)
                  {
                       case Key.Up:
                           datePicker.Increment(TimeSpan.FromDays(1)); 
                           break;
    
                       case Key.Down:
                           datePicker.Decrement(TimeSpan.FromDays(1));
                           break;
                   }
             }
    }
    
    

    Just in case required, you can use arrow keys in the Calendar present in the C1DatePicker’s DropDown.

    Please refer to the same from the attached sample. (see DatePickerUpDownKeys.zip)

    Regards,

    Kartik

    DatePickerUpDownKeys.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels