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

How do I catch filter exceptions?

7 Answers 348 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erik Van Norstrand
Top achievements
Rank 1
Erik Van Norstrand asked on 21 Jul 2010, 05:17 PM
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

7 Answers, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 27 Jul 2010, 10:01 AM
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
0
Anisha
Top achievements
Rank 1
answered on 26 Aug 2010, 01:36 PM
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

0
Alexander
Telerik team
answered on 30 Aug 2010, 09:46 PM
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
0
Anisha
Top achievements
Rank 1
answered on 30 Aug 2010, 10:01 PM
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
0
Alexander
Telerik team
answered on 02 Sep 2010, 04:34 PM
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
0
Brandon
Top achievements
Rank 1
answered on 19 Mar 2013, 12:44 AM
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
0
Svett
Telerik team
answered on 20 Mar 2013, 02:32 PM
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.
Tags
GridView
Asked by
Erik Van Norstrand
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Anisha
Top achievements
Rank 1
Brandon
Top achievements
Rank 1
Svett
Telerik team
Share this question
or