New to Telerik UI for WinForms? Start a free 30-day trial
Filter when Enter is pressed in RadVirtualGrid
Updated over 1 year ago
Environment
| Product Version | Product | Author |
|---|---|---|
| 2019.3.917 | RadVirtualGrid for WinForms | [Nadya Karaivanova] |
Description
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.
Solution
To achieve this you need to handle the CellEditorInitialized event and get access to the VirtualGridTextBoxEditor. Then, check if Enter is pressed in order to perform the filtering operation. The SynchronizeRows method will fire the CellValueNeeded event, and all the cells will be populated again with data. This is demonstrated in the following code snippet.
Filter on Enter
C#
BindingSource bs = new BindingSource();
private void RadVirtualGrid1_CellEditorInitialized(object sender, VirtualGridCellEditorInitializedEventArgs e)
{
if (e.RowIndex == RadVirtualGrid.FilterRowIndex)
{
VirtualGridTextBoxEditor editor = e.ActiveEditor as VirtualGridTextBoxEditor;
RadTextBoxEditorElement el = editor.EditorElement as RadTextBoxEditorElement;
el.KeyDown -= El_KeyDown;
el.KeyDown += El_KeyDown;
}
}
private void El_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
bs.Filter = this.radVirtualGrid1.FilterDescriptors.Expression;
radVirtualGrid1.RowCount = bs.List.Count;
radVirtualGrid1.VirtualGridElement.TableElement.SynchronizeRows();
}
}