To reproduce:
- Add date time column to a grid and set the MaskType to FreeFormDateTime (this can be done by accessing the editor in the CellEditorInitialized event).
- Type a year in the editor and click the right arrow key until the cell is changed.
Workaround:
class MyRadDateTimeEditor : RadDateTimeEditor
{
bool isRightmostMaskItemSelected = false;
public override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
FreeFormDateTimeProvider provider = ((RadDateTimeEditorElement) this.EditorElement).TextBoxElement.Provider as FreeFormDateTimeProvider;
if (provider.TextBoxItem.SelectionStart == provider.TextBoxItem.Text.Length)
{
this.isRightmostMaskItemSelected = true;
}
}
else
{
base.OnKeyDown(e);
}
}
protected override void OnKeyUp(KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
if (isRightmostMaskItemSelected)
{
isRightmostMaskItemSelected = false;
GridDateTimeCellElement cell = this.OwnerElement as GridDateTimeCellElement;
cell.GridControl.EndEdit();
}
}
else
{
base.OnKeyUp(e);
}
}
}
void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
if (editor != null)
{
var editorElement = editor.EditorElement as RadDateTimeEditorElement;
editorElement.TextBoxElement.MaskType = MaskType.FreeFormDateTime;
}
}