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

After refresh the grid, the search text is cleared

1 Answer 246 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 06 Nov 2019, 10:52 AM

Hello,

We are working with 2019 Q2.

When the grid is refreshed (grid.MasterTemplate:Refresh() or bound to a new datasource), a new GridSearchCellElement is created (CreateCell event is fired) and the search text is cleared.

Is it possible to change this behaviour and don't touch the the GridSearchCellElement - object?

Currently I set the searchtext again, but this is not really an option for us.

We bypassed the default search and have implemented a new logic. After search is completed a refresh or rebind is done. This works fine, but problem starts when the user keeps typing while the search is executed. In this scenario some letters are lost (we are working with Progress - so it is a single threaded environment).

I hope you can help us with this.

Regards,
Martin

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Nov 2019, 01:10 PM
Hello, Martin, 

It is expected behavior that when you rebind the grid (set a new DataSource collection), the search row to be recreated.

The possible solution that I can suggest is to keep the search criteria and restore it after the rebind operation. The following code snippet demonstrates a sample approach: 
        public RadForm1()
        {
            InitializeComponent();  
             
            this.radGridView1.AllowSearchRow = true;  
        }

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

        private void searchCell_TextChanged(object sender, EventArgs e)
        {
            GridSearchCellTextBoxElement textbox = sender as GridSearchCellTextBoxElement;
            this.radGridView1.Tag = textbox.TextBoxItem.Text;
        }
        private void radButton1_Click(object sender, EventArgs e)
        { 
            string searchText = this.radGridView1.Tag + "";
            this.radGridView1.MasterView.TableSearchRow.Search("");
            
            this.radGridView1.DataSource = null;
            this.radGridView1.DataSource = this.productsBindingSource;
        
            if (searchText != string.Empty)
            {
                this.radGridView1.MasterView.TableSearchRow.Search(searchText);
            }
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or