Completed
Last Updated: 23 Feb 2016 07:05 by ADMIN
ADMIN
Dimitar
Created on: 08 Feb 2016 15:02
Category: GridView
Type: Bug Report
0
FIX. RadGridView - exception when free form date time parsing functionality is used and the cell is changed with the right key.
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;
    }
}
0 comments