I have a column in a DataView that contains NaN. When I attempt to Sort on
this column, I get:
MESSAGE: Index was outside the bounds of the array.
SOURCE: System.Data
STACKTRACE:
at System.Data.Index.Sort(Int32 left, Int32 right)
at System.Data.Index.InitRecords()
at System.Data.Index..ctor(DataTable table, Int32[] indexDesc,
DataViewRowState recordStates, IFilter rowFilter)
at System.Data.DataTable.GetIndex(Int32[] indexDesc, DataViewRowState
recordStates, IFilter rowFilter)
at System.Data.DataTable.GetIndex(String sort, DataViewRowState
recordStates, IFilter rowFilter)
at System.Data.DataView.UpdateIndex(Boolean force)
at System.Data.DataView.SetIndex(String newSort, DataViewRowState
newRowStates, DataFilter newRowFilter)
at System.Data.DataView.set_Sort(String value)
Here is my repro code:
public static void sortDataView()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("bar",Type.GetType("System.Double")));
dt.Columns.Add(new DataColumn("foo",Type.GetType("System.Double"),
"bar / 0"));
dt.Rows.Add(new Object[]{0});
dt.Rows.Add(new Object[]{0});
dt.DefaultView.Sort = "foo ASC"; // <-- This Line Errors!
}
However, if I debug with VS.NET 2003 and break just before the sort command
and run it in the Command Window, then continue, there is no error. I just
copied the line from the source that errors into the Command Window and it
executes just fine. I continue and my app runs without errors.
How do I fix this? (Besides fixing my divide by zero error)
thanks
-ivan.