Behavior when editing dates

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    4 posts
    Member since:
    Sep 2008

    Posted 27 Jul 2015 Link to this post

    We would like to change the behavior of the RadDateTimeEditorElement when entering a date via the keyboard.

    Depending on the location the application is used in, the date will be entered in either dd/MMM/yyyy format or dd/MM/yyyy format.

    Lets use dd/MMM/yyyy format as an example...

    When clicking on the MMM section of the date, user should be able to key in "JAN" or "FEB", etc.   Currently when they enter "J" and want to get to July, they have to press "J" several times to get to it.  Pressing "A" after the "J" would take them to "APR".   Other date controls in the application do not behave this way so the users are a little frustrated.

    When clicking on the yyyy section of the date, the year rolls as the keyboard is being pressed.   So if the date was 1973 and the user wanted it to change to 2015, they would see 2197... 2019... 2011.. 2015.      The users see this as high risk for error.

     Basically, the user wants to be able to key in an entire date (with the format restricted) and it be validated when entry is completed.

     I'm sure we can override the events in order to do something like this, whether it be on the keypress/keydown/keyup events... but because the entire section of the date is always selected, I'm unsure how to do this.... or maybe it's a completely different event I should be looking at altogether. 

    Any help would be appreciated.

     Thanks

     

     

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 28 Jul 2015 Link to this post

    Hi Jeff,

    Thank you for writing.

    We provide out of the box support for a special FreeFormDateTime mask type, more information is available in the following documentation article: Free Form DateTime Parsing.

    Besides usages in RadDateTimePicker and RadTimePicker controls, this feature can also be utilized in the editor of a GridViewDateTimeColumn in RadGridView. Please check my code snippet below: 
    public Form1()
    {
        InitializeComponent();
     
        this.radGridView1.DataSource = this.GetData();
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
        this.radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;
     
        GridViewDateTimeColumn dateTimeColumn = this.radGridView1.Columns[3] as GridViewDateTimeColumn;
        dateTimeColumn.Format = DateTimePickerFormat.Custom;
        dateTimeColumn.CustomFormat = "dd-MMM-yyyy";
        dateTimeColumn.FormatString = "{0:dd-MMM-yyyy}";
    }
     
    private void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
    {
        RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
        if (editor != null)
        {
            RadDateTimeEditorElement element = editor.EditorElement as RadDateTimeEditorElement;
            element.TextBoxElement.MaskType = MaskType.FreeFormDateTime;
        }
    }

    I am also sending you a gif file showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    4 posts
    Member since:
    Sep 2008

    Posted 28 Jul 2015 in reply to Hristo Merdjanov Link to this post

    Yes, this helps... and is closer to what I'm looking for.   However, when I blank out the text, I would expect the date to null out.... currently it gets set to "01/Jan/0001".   If I go to the calendar to clear it, it gets set to todays date.

     We are on v2014.2.715.40 release currently.   I don't know if this behaves differently in newer versions.   Unfortunately, due to the amount of QA that is required for our applications when upgrading to a newer version... an upgrade would not be possible this year.

     Thanks

  5. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 29 Jul 2015 Link to this post

    Hello Jeff,

    Thank you for writing back.

    Please check the following resources as they provide additional information about the properties of RadDateTimePicker and how null values can be handled. This is also applicable to the editor of a GridViewDateTimeColumn ​in RadGridView:
    1. http://www.telerik.com/help/winforms/editors-datetimepicker-basics-raddatetimepicker-properties.html
    2. http://www.telerik.com/help/winforms/editors-datetimepicker-how-to-set-null-or-empty-value.html

    I hope this information is useful. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top