How do I catch filter exceptions?

8 posts, 1 answers
  1. Erik Van Norstrand
    Erik Van Norstrand avatar
    3 posts
    Member since:
    Apr 2010

    Posted 21 Jul 2010 Link to this post

    Hey all,

    So here is my situation:

    I have a column that is of type double. If I "accidentally" enter in characters into the filter, I get an exception thrown that says: "FilterExpressionException" unhandled.

    Where do I handle this?

    Thanks,
    Erik Van Norstrand
  2. Answer
    Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 27 Jul 2010 Link to this post

    Hello Erik,

    Thank you for contacting us.

    Please review the following approach for handling FilterExpressionException-s:
    try
    {
        FilterDescriptor filter = new FilterDescriptor();
        filter.PropertyName = "column1";
        filter.Operator = FilterOperator.IsGreaterThan;
        filter.Value = "12.t"; // incorrect value, will cause FilterExpressionException
        filter.IsFilterEditor = true;
        this.radGridView1.FilterDescriptors.Add(filter);
    }
    catch (FilterExpressionException ex)
    {
        FilterDescriptor wrongFilter = this.radGridView1.Columns["column1"].FilterDescriptor;
        double correctValue = 12.5;
        FilterDescriptor filterDescriptor =
            new FilterDescriptor(wrongFilter.PropertyName, wrongFilter.Operator, correctValue);
        filterDescriptor.IsFilterEditor = wrongFilter.IsFilterEditor;
     
        this.radGridView1.FilterDescriptors.Remove(wrongFilter);
        this.radGridView1.FilterDescriptors.Add(filterDescriptor);
    }

    Please confirm if this approach is useful in your particular case.

    Best regards,
    Alexander
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Anisha
    Anisha avatar
    5 posts
    Member since:
    Apr 2009

    Posted 26 Aug 2010 Link to this post

    Hey all,
    The approach you've shown handles exceptions when filter is added programmatically. How do i handle errors caused by users entering incorrect expressions in the filter editor box?
    Thanks
    Anisha

  4. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 30 Aug 2010 Link to this post

    Hello Anisha,

    Thank you for your question.

    Unfortunately, there is no entry point for handling invalid filter cells' expression in RadGridView. We are working on preventing input of incorrect data in the filter row. Please, could you report the cases in which this mechanism fails? It will help us very much to improve it further.

    Best regards,
    Alexander
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Anisha
    Anisha avatar
    5 posts
    Member since:
    Apr 2009

    Posted 30 Aug 2010 Link to this post

    One of the problems i'm having, was that the filteroperator does not get updated properly when datasource changes on a grid. 
    http://www.telerik.com/community/forums/winforms/gridview/update-just-the-filtering-on-radgridview.aspx

    Another thing, it shouldnt throw exceptions when I enter a number in a filter which shows up for an Int32 column with a Contains type of FilterOperator.

    Thanks
    Anisha
  6. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 02 Sep 2010 Link to this post

    Hello Anisha,

    Thank you for writing back.

    Please review my answer to your forum post. The exception you see is because of the wrong filter operator. Operator "Contains" could not be applied to an integer column even with a number value.

    Thank you for your time and feedback.

    Best regards,
    Alexander
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Brandon
    Brandon avatar
    10 posts
    Member since:
    Oct 2012

    Posted 18 Mar 2013 Link to this post

    Hey,

    I'm seeing the same exception, which actually crashes our entire app, when the user attempts to do a "LIKE" operation on a DateTime column.  Has this been fixed?  Any workarounds?

    I'm using Q1 2013 release.

    Thanks in advance--
    Brandon
  8. Svett
    Admin
    Svett avatar
    728 posts

    Posted 20 Mar 2013 Link to this post

    Hi Brandon,

    This is not an issue. The like operation is not valid filter expression for
    DateTime values. Nevertheless, you can use a custom filtering approach to achieve the desired behavior. You can read more about it in the online documentation.

    Greetings,
    Svett
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top