Showing only search results

4 posts, 0 answers
  1. safa
    safa avatar
    2 posts
    Member since:
    Jul 2019

    Posted 16 Jul Link to this post

         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?

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3451 posts

    Posted 16 Jul Link to this post

    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.
  3. safa
    safa avatar
    2 posts
    Member since:
    Jul 2019

    Posted 16 Jul Link to this post

    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.
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3451 posts

    Posted 17 Jul Link to this post

    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.
Back to Top