New to Telerik UI for WinFormsStart a free 30-day trial

Filter when Enter is pressed

Updated over 1 year ago

By default the filtering operation is performed on every keystroke. However a common case is to perform the filtering operation after the value is entered, for example when Enter is pressed. To achieve this you need to cancel the filtering operation until Enter is pressed. This is demonstrated in the following code snippet.

The AutoFilterDelay property gets or sets a value in milliseconds that indicates the delay between the last key press and the filtering operation (available since R1 2019 SP1).

Cancel filtering until Enter is pressed.

C#
private bool EnterPress = false;
private void radGridView1_FilterChanging(object sender, GridViewCollectionChangingEventArgs e)
{
    if (!EnterPress)
    {
        e.Cancel = true;
    }
    EnterPress = false;
}
private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    if (e.Row is GridViewFilteringRowInfo)
    {
        RadTextBoxEditor ed = e.ActiveEditor as RadTextBoxEditor;
        RadTextBoxEditorElement el = ed.EditorElement as RadTextBoxEditorElement;
        el.KeyDown -= el_KeyDown;
        el.KeyDown += el_KeyDown;
    }
}
private void el_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        EnterPress = true;
    }
}

See Also

In this article
See Also
Not finding the help you need?
Contact Support