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!