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

After refresh the grid, the search text is cleared

1 Answer 409 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.
Hamzah
Top achievements
Rank 1
commented on 26 Feb 2025, 08:41 AM

Hi Dess,

that looks like a problem I have too. Is there a way to this strictly in MVVM?

Thanks in advance (:

Dinko | Tech Support Engineer
Telerik team
commented on 27 Feb 2025, 01:55 PM

Telerik UI for WinForms does not provide an API to implement the MVVM pattern. The MVVM pattern is more applicable to WPF. I am afraid that I can't suggest a way to implement this strictly in MVVM.

Generally speaking, Microsoft has introduced some data binding improvements with .Net 8. We have a feature request logged in our Feedback Portal to adopt these changes. You can vote for its implementation to increase its priority.

Hamzah
Top achievements
Rank 1
commented on 27 Feb 2025, 02:26 PM

Hi Dinko, 

I forgot this question was asked in the WinUI section. I am working in a WPF application, does that change your answer?

 

Martin Ivanov
Telerik team
commented on 12 Mar 2025, 08:11 AM

The approach provided in this forum is not applicable for RadGridView for WPF. In the context of WPF you will still need to cache the search text and restore it after the data refresh, but you should use different code. I've attached a sample project to show this. I hope it helps.

 

Hamzah
Top achievements
Rank 1
commented on 12 Mar 2025, 10:25 AM

Hi there Martin, 

your sample project fixed the issue, thanks a lot!

Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or