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

Cant able to clear filter value in GridViewDateTimeColumn

3 Answers 109 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vino
Top achievements
Rank 1
Vino asked on 07 Mar 2013, 05:11 AM
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.

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 11 Mar 2013, 12:55 PM
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.
0
Vino
Top achievements
Rank 1
answered on 12 Mar 2013, 04:49 AM
Thanks Stefan,

        For Backspace key it wont work. I changed the code little bit and Its working fine.
0
Stefan
Telerik team
answered on 14 Mar 2013, 11:25 AM
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.
Tags
GridView
Asked by
Vino
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Vino
Top achievements
Rank 1
Share this question
or