Issue with Filters when added programmatically

6 posts, 1 answers
  1. Mohammed
    Mohammed avatar
    19 posts
    Member since:
    Jan 2016

    Posted 05 Aug Link to this post

    I have a requirement to add a default filter to the my GridView.  Therefore I do this simply using the following code:

                FilterDescriptor filterDescriptor = new FilterDescriptor();
                filterDescriptor.PropertyName = "DistributionStatus";
                filterDescriptor.Value = "Active";
                filterDescriptor.Operator = FilterOperator.IsNotEqualTo;
                filterDescriptor.IsFilterEditor = true;

    This is simply code taken from the documentation and modified.

    This applies the restriction that I require, but when I open up the filter on screen as a user, I do not see all the values available in the column, so I am unable to remove this filter... Please see attached file (1.png) for an example.

    If however, I add a random filter that does not affect the results (2.png), I now see all my available options (3.png).  Can anyone suggest if this is a bug? or maybe a setting I need to update or a forced refresh of some kind?

  2. Mohammed
    Mohammed avatar
    19 posts
    Member since:
    Jan 2016

    Posted 08 Aug Link to this post

    Telerik, can you confirm if this is a bug please?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dess
    Admin
    Dess avatar
    1605 posts

    Posted 08 Aug Link to this post

    Hello Mohammed,

    Thank you for writing. 

    I would like to note that the basic filtering and the excel like filtering have a difference in their filtering logic. Hence, the applied filter are different. The Excel-Like filtering is designed to perform cascade filtering via the UI and it uses CompositeFilterDescriotors. In order to achieve your requirement, you must apply the following filter: 
    FilterDescriptor filterDescriptor = new FilterDescriptor();
    filterDescriptor.PropertyName = "Title";
    filterDescriptor.Value = "Sales Representative";
    filterDescriptor.Operator = FilterOperator.IsNotEqualTo;
     
    CompositeFilterDescriptor cfd = new CompositeFilterDescriptor();
    cfd.LogicalOperator = FilterLogicalOperator.And;
    cfd.FilterDescriptors.Add(filterDescriptor);    
    cfd.IsFilterEditor = true;
    this.radGridView1.FilterDescriptors.Add(cfd);

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  5. Mohammed
    Mohammed avatar
    19 posts
    Member since:
    Jan 2016

    Posted 15 Aug Link to this post

    Hi Dess,

    Thanks for the reply, but unfortunately, this still causes the same issue.  Here is my code verbatim:

                FilterDescriptor filterDescriptorRemoved = new FilterDescriptor();
                filterDescriptorRemoved.PropertyName = "DistributionStatus";
                filterDescriptorRemoved.Value = "Removed";
                filterDescriptorRemoved.Operator = FilterOperator.IsNotEqualTo;

                CompositeFilterDescriptor cfd = new CompositeFilterDescriptor();
                cfd.LogicalOperator = FilterLogicalOperator.And;
                cfd.FilterDescriptors.Add(filterDescriptorRemoved);
                cfd.IsFilterEditor = true;

                radGrdVwBookings.FilterDescriptors.Add(cfd);

    It seems this creates a custom filter, which removes the valid selections from the list.  In this case I only see the 'Active' value which is checked... I would expect to see:

    Active - Checked
    Removed - Not Checked

    Instead I just see 

    Active - Checked (See 4.png)

    Therefore have no option to include the 'Removed' rows.

    I have found that the Clear Filter option (see arrow on 4.png) resets the values and the 'Removed' value then appears... it is a work around, but suspect users will be confused by this and at a glance simply assume there are no 'Removed' entries in the grid.

    Is there any other way of creating filters so all valid values appear, but only certain ones are checked?

    Thanks

  6. Answer
    Dess
    Admin
    Dess avatar
    1605 posts

    Posted 16 Aug Link to this post

    Hello Mohammed, 

    Thank you for writing back. 

    I have missed to include in the code snippet from my previous post a very important code line specifying the ExcelFilteredColumns
    FilterDescriptor filterDescriptor = new FilterDescriptor();
    filterDescriptor.PropertyName = "Title";
    filterDescriptor.Value = "Sales Representative";
    filterDescriptor.Operator = FilterOperator.IsNotEqualTo;
     
    CompositeFilterDescriptor cfd = new CompositeFilterDescriptor();
    cfd.LogicalOperator = FilterLogicalOperator.And;
    cfd.FilterDescriptors.Add(filterDescriptor);    
    cfd.IsFilterEditor = true;
    this.radGridView1.FilterDescriptors.Add(cfd);
     
    this.radGridView1.MasterTemplate.ExcelFilteredColumns.Add(this.radGridView1.Columns["Title"]);

    Now, you are supposed to achieve the desired result. I have attached my sample project for your reference.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  7. Mohammed
    Mohammed avatar
    19 posts
    Member since:
    Jan 2016

    Posted 16 Aug in reply to Dess Link to this post

    Thank you Dess!  The last line did the trick!

    Issue resolved... Thanks again!

Back to Top
UI for WinForms is Visual Studio 2017 Ready