I get an array index out of range exception when removing the last row in a datatable in WPF. Removing other rows is ok, but trying to remove the last row triggers this problem. What is wrong here?
public void removeRow(int index)
{
if (index < 0)
{
index = 0;
}
myDataTable.Rows.RemoveAt(index);
myDataTable.AcceptChanges();
}
I also tried selectedDataRow.delete()
and myDataTable.remove(selectedDataRow)
but they have the same problem.