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

Behavior when editing dates

3 Answers 185 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 27 Jul 2015, 06:05 PM

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

 

 

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 28 Jul 2015, 01:16 PM
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
0
Jeff
Top achievements
Rank 1
answered on 28 Jul 2015, 04:22 PM

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

0
Hristo
Telerik team
answered on 29 Jul 2015, 12:47 PM
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
Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or