internal void DataChanged(DataRowChangeEventArgs args)
{
if ((!_started) || (_rowCounter == -1 && !_tableCleared))
{
return;
}
switch (args.Action)
{
case DataRowAction.Add:
ValidateRow(_rowCounter + 1);
if (_currentDataRow == _currentDataTable.Rows[_rowCounter + 1])
{
// check if we moved one position up
_rowCounter++; // if so, refresh the datarow and fix the counter
}
break;
case DataRowAction.Delete: // delete
case DataRowAction.Rollback:// rejectchanges
case DataRowAction.Commit: // acceptchanges
if (args.Row.RowState == DataRowState.Detached)
{
if (args.Row != _currentDataRow)
{
if (_rowCounter == 0) // if I am at first row and no previous row exist,NOOP
break;
ValidateRow(_rowCounter - 1);
if (_currentDataRow == _currentDataTable.Rows[_rowCounter - 1])
{
// one of previous rows is detached, collection size is changed!
_rowCounter--;
}
}
else
{ // we are proccessing current datarow
_currentRowRemoved = true;
if (_rowCounter > 0)
{
// go back one row, no matter what the state is
_rowCounter--;
_currentDataRow = _currentDataTable.Rows[_rowCounter];
}
else
{
// we are on 0th row, so reset data to initial state!
_rowCounter = -1;
_currentDataRow = null;
}
}
}
break;
default:
break;
}
}
}