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

Showing only search results

3 Answers 169 Views
GridView
This is a migrated thread and some comments may be shown as answers.
safa
Top achievements
Rank 1
safa asked on 16 Jul 2019, 10:35 AM

     Hello there,

I'm using radgridview.It only highlights search results , but I want to hide all records except search results.Is there a way to do it? If so how can I do it?

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Jul 2019, 11:25 AM
Hello, Safa,  

The purpose of the search functionality is to highlight the results and still show the rest of the records. If you need to hide the rows that doesn't match the search criteria, it is appropriate to use the custom filtering functionality that RadGridView offers: https://docs.telerik.com/devtools/winforms/controls/gridview/filtering/custom-filtering

Please refer to the Demo application >> GridView >> Filtering >> Custom filtering example which demonstrates how to achieve the desired behavior. The Demo application is located in the installation folder of the suite which usually can be found at the following path: C:\Program Files (x86)\Progress\Telerik UI for WinForms R2 2019\Examples\QuickStart\Bin

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.
0
safa
Top achievements
Rank 1
answered on 16 Jul 2019, 05:48 PM
I have more than 5000 records , I've tried this method but it made my program slow.While I'm trying to search smt. , it doesn't respond for a few seconds.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Jul 2019, 01:43 PM
Hello, Safa,  

Indeed, the search behavior is much faster because it uses a BackgroundWorker for searching the results. However, there is no straight-forward way for hiding the rows that doesn't match the search criteria. Only the filtering (basic or custom) will do the job. 

If the custom filtering doesn't produce the performance that you wish, I can suggest you to combine the searching and filtering functionality. Handle the MasterView.TableSearchRow.SearchProgressChanged event and when the SearchProgressChangedEventArgs.SearchFinished argument is true, you can add a CompositeFilterDescriptor which contains as many FilterDescriptors as the columns in RadGridView are. You should use FilterLogicalOperator.Or for the CompositeFilterDescriptor in order to ensure that the row will be visible if at least one column match the criteria. The following code snippet illustrates better my idea. However, have in mind that this approach is suitable if all columns are of text type. For the different column types, you need to add the respective FilterOperator:

private void RadForm1_Load(object sender, EventArgs e)
{
    this.radGridView1.AllowSearchRow = true;
    this.radGridView1.EnableFiltering = true;
 
    this.radGridView1.MasterView.TableSearchRow.SearchProgressChanged += TableSearchRow_SearchProgressChanged;
}
 
private void TableSearchRow_SearchProgressChanged(object sender, SearchProgressChangedEventArgs e)
{
    if (e.SearchFinished)
    {
        this.radGridView1.FilterDescriptors.Clear();
        if (e.SearchCriteria != string.Empty)
        {
            CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
            foreach (GridViewColumn col in this.radGridView1.Columns)
            {
                compositeFilter.FilterDescriptors.Add(new FilterDescriptor(col.FieldName, FilterOperator.Contains, e.SearchCriteria));
            }
            compositeFilter.LogicalOperator = FilterLogicalOperator.Or;
            this.radGridView1.FilterDescriptors.Add(compositeFilter);
        }
    }
}

Should you have further questions please let me know.

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
safa
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
safa
Top achievements
Rank 1
Share this question
or