Move to Following Date Part on Data Entry in DateTimePicker

不想你离开。 提交于 2019-12-07 20:09:54

问题


I have a user request that I'm trying to accommodate, the simplest way I can think to explain is to use illustrate with a picture:

Essentially the user is typing a ton of dates in. Instead of typing the

MM [Backslash (Or Right Arrow)]
DD [Backslash]
YYYY [Backslash] etc ...

They'd like to Key the value and be moved to the next Date Part Value. While this doesn't seem like much I can imagine it adds up to allot of additional keystrokes and takes the end user off the number pad. I'm currently using Telerik's Winform RadDateTimePicker with Custom Format:

MM/dd/yyyy hh:mm tt

but would not be opposed to changing to the Winforms DateTimePicker.

Can anyone suggest an elegant solution for this ? The only thing I can currently think of is catching the keystrokes when the control is in focus but I feel like this could be messy.

Thankyou


回答1:


  1. RadMaskedEditBox (and respectively RadDateTimeEditor, which uses RadMaskedEditBox internally), have build in functionality to select the next part, however, it seems it does not work correctly with this mask, so I reported it as an issue. Here is the link to it: issue link. You can subscribe for status change alerts in order to get notified once its done.

  2. What you can look at is the free form date time parsing introduced recently. It allows you to type in "10162014" which will get parsed to "10\16\2014". More information no parsing dates is available here: Parsing Dates

  3. And the last thing would be to work with KeyDown and manually move the selection. There is API for this on the provider. Here is how to access it:

    (this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.Provider as MaskDateTimeProvider).SelectNextEditableItem();
    

I hope some of this works for you.




回答2:


This is not intended to be a link answer but I have to refer to the Telerik documentation to allow the OP to customize the control according to his needs.

My understanding is that your customer needs to type the date and time in a specific culture avoiding to type the separators. You should use the maskedEditBox which already have a mask for your need MM/dd/yyyy hh:mm tt Particularly you should set the pattern "s" which correspond to "Sortable date time pattern (based on ISO 8601) using local time"

Have a look at Telerik documentation here to set up your control as needed and the relevant validator. This should solve your problem.

This is how it looks when empty:

and this si show it appears when filled in:

Using the relevant event (I have used radMaskedEditBox1_Leave) you can still use also a dateTimePicker taking the input from the radMasketTextBox:

dateTimePicker1.Format = DateTimePickerFormat.Custom;    
dateTimePicker1.CustomFormat = "dd/MM/yyyy HH:mm ss";

dateTimePicker1.Text = radMaskedEditBox1.Text;



回答3:


Please check below URL fiddle URL for datetime mask:

1]. http://jsfiddle.net/jensbits/3yUes/light/ 2]. http://jsfiddle.net/LkpPJ/5/



来源:https://stackoverflow.com/questions/26517023/move-to-following-date-part-on-data-entry-in-datetimepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!