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

RadGridView Deferred Search on Tab key

Updated over 6 months ago

Environment

Product VersionProductAuthor
2019.2.618RadGridView for WinFormsDesislava Yordanova

Description

GridViewSearchRowInfo offers the DeferredSearch property which indicates whether the grid control will wait until the Enter key is pressed before a new search operation is started. Its default value is false.

However, if it is enabled, you may prefer to use the Tab key to trigger the search functionality.

Solution

Handle the ViewCellFormatting event where you have access to the GridSearchCellElement . Then, subscribe to the GridSearchCellElement.SearchTextBox.KeyUp event and detect when the Tab key is pressed and call the TableSearchRow.Search method with the entered text:

Search on Tab

C#

         public RadForm1()
        {
            InitializeComponent();

            this.radGridView1.ViewCellFormatting += radGridView1_ViewCellFormatting;
            this.radGridView1.AllowSearchRow = true;
            this.radGridView1.MasterView.TableSearchRow.DeferredSearch = true;
        }

        private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            GridSearchCellElement searchCell = e.CellElement as GridSearchCellElement;
            if (searchCell != null)
            {
                searchCell.SearchTextBox.KeyUp -= SearchTextBox_KeyUp;
                searchCell.SearchTextBox.KeyUp += SearchTextBox_KeyUp;
            }
        }

        private void SearchTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            GridSearchCellTextBoxElement searchBox = sender as GridSearchCellTextBoxElement;
            if (e.KeyData == Keys.Tab && this.radGridView1.MasterView.TableSearchRow.DeferredSearch)
                this.radGridView1.MasterView.TableSearchRow.Search(searchBox.Text);
        }        
       

See Also