/// <summary>
/// Removes the specified DataColumn object from the collection.
/// </summary>
/// <param name="column">The DataColumn to remove.</param>
public void Remove(DataColumn column)
{
if (column == null)
{
throw new ArgumentNullException("column", "'column' argument cannot be null.");
}
if (!Contains(column.ColumnName))
{
throw new ArgumentException("Cannot remove a column that doesn't belong to this table.");
}
string dependency = GetColumnDependency(column);
if (dependency != String.Empty)
{
throw new ArgumentException("Cannot remove this column, because it is part of " + dependency);
}
#if NOT_PFX
CollectionChangeEventArgs e = new CollectionChangeEventArgs(CollectionChangeAction.Remove, column);
#endif
int ordinal = column.Ordinal;
UnregisterName(column.ColumnName);
base.List.Remove(column);
// Reset column info
column.ResetColumnInfo();
//Update the ordinals
for (int i = ordinal; i < this.Count; i++)
#if NET_2_0
{ this[i].Ordinal = i; }
#else
{ this[i].SetOrdinal(i); }
#endif
if (parentTable != null)
{
parentTable.OnRemoveColumn(column);
}
if (column.AutoIncrement)
{
autoIncrement.Remove(column);
}
column.PropertyChanged -= new PropertyChangedEventHandler(ColumnPropertyChanged);
#if NOT_PFX
OnCollectionChanged(e);
#endif
}