Cant able to clear filter value in GridViewDateTimeColumn

4 posts, 0 answers
  1. Vino
    Vino avatar
    4 posts
    Member since:
    Mar 2012

    Posted 06 Mar 2013 Link to this post

    HI,
     
        I am not able to clear filter value in GridViewDateTimeColumn while pressing delete key or backspace key. Instead of clear  it resets to default date. Whether can we set any key down event explicitly in that DateTimePIcker or was there any other way to clear filter value when press delete key.
  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 11 Mar 2013 Link to this post

    Hello Vino,

    Thank you for writing.

    When you press the Delete or Backspace key while the editor is opened, the selected element (year, month, day) will fall back to its minimum. You can clear the editor by handling the KeyDown event of the editor element and using the SetToNullValue method of the element:
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
        if (editor != null)
        {
            RadDateTimeEditorElement el = (RadDateTimeEditorElement)editor.EditorElement;
            el.KeyDown -= el_KeyDown;
            el.KeyDown += el_KeyDown;
        }
    }
     
    void el_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyData == Keys.Delete || e.KeyData == Keys.Back)
        {
            e.Handled = true;
            RadDateTimeEditorElement el = (RadDateTimeEditorElement)sender;
            el.SetToNullValue();
        }
    }

    I hope that you find this information useful.
     
    All the best,
    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  3. Vino
    Vino avatar
    4 posts
    Member since:
    Mar 2012

    Posted 11 Mar 2013 Link to this post

    Thanks Stefan,

            For Backspace key it wont work. I changed the code little bit and Its working fine.
  4. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 14 Mar 2013 Link to this post

    Hi Vino,

    Sorry for the confusion- I mixed up the events, you should use the KeyUp event instead. Here is the code snippet so the community can benefit from it:
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
        if (editor != null)
        {
            RadDateTimeEditorElement el = (RadDateTimeEditorElement)editor.EditorElement;
            el.KeyUp -= el_KeyUp;
            el.KeyUp += el_KeyUp;
        }
    }
     
    void el_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyData == Keys.Delete || e.KeyData == Keys.Back)
        {
            e.Handled = true;
            RadDateTimeEditorElement el = (RadDateTimeEditorElement)sender;
            el.SetToNullValue();
        }
    }

    All the best,

    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top