troubleshooting Question

DataView RowFilter raises the IndexOutOfRangeException exception ... how to avoid this error?

Avatar of bek
bekFlag for United States of America asked on
.NET ProgrammingC#Visual Basic.NET
18 Comments1 Solution697 ViewsLast Modified:
I am using DataView.RowFilter to filter a DataTable, but when there are no results in the filter, an IndexOutOfRangeException is raised.  This seems to be normal .NET behavior, from what I am seeing on the web.  It is perfectly normal for my filter results to have 0 matches, and I don't want to see this error message whenever no results are found.  Here is my line of code:

      dv.RowFilter = "PositionID like '" + PositionNumber + "%'";

I dislike this solution, but I was going to put a try/catch around this line and just swallow the error, but the try/catch does NOT catch the error!  I read online that an event is raised, and the error occurs in this event, and that's why the try/catch doesn't work.  Someone else recommended I put a try/catch around the code in my Main program, but doesn't doesn't catch it, either.

Can someone recommend a way to handle this error?  A simple code example would be nice.  I'd prefer to handle it without a try/catch, but I'll take any solution that works!

Thanks,
Brian
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 18 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros