public void Clear()
{
int oldLength = _list.Count;
DataColumn[] columns = new DataColumn[_list.Count];
_list.CopyTo(columns, 0);
OnCollectionChanging(s_refreshEventArgs);
if (_table.fInitInProgress && _delayedAddRangeColumns != null)
{
_delayedAddRangeColumns = null;
}
try
{
// this will smartly add and remove the appropriate tables.
_fInClear = true;
BaseGroupSwitch(columns, oldLength, null, 0);
_fInClear = false;
}
catch (Exception e) when (ADP.IsCatchableOrSecurityExceptionType(e))
{
// something messed up: restore to old values and throw
_fInClear = false;
BaseGroupSwitch(null, 0, columns, oldLength);
_list.Clear();
for (int i = 0; i < oldLength; i++)
{
_list.Add(columns[i]);
}
throw;
}
_list.Clear();
_table.ElementColumnCount = 0;
OnCollectionChanged(s_refreshEventArgs);
}