/// <summary> /// Creates and adds the specified DataColumn object to the DataColumnCollection. /// </summary> /// <param name="column">The DataColumn to add.</param> public void Add(DataColumn column) { if (column == null) throw new ArgumentNullException ("column", "'column' argument cannot be null."); if (column.ColumnName.Equals(String.Empty)) { column.ColumnName = GetNextDefaultColumnName (); } // if (Contains(column.ColumnName)) // throw new DuplicateNameException("A DataColumn named '" + column.ColumnName + "' already belongs to this DataTable."); if (column.Table != null) throw new ArgumentException ("Column '" + column.ColumnName + "' already belongs to this or another DataTable."); CollectionChangeEventArgs e = new CollectionChangeEventArgs(CollectionChangeAction.Add, this); column.SetTable (parentTable); RegisterName(column.ColumnName, column); int ordinal = base.List.Add(column); column.SetOrdinal (ordinal); // if table already has rows we need to allocate space // in the column data container if ( parentTable.Rows.Count > 0 ) { column.DataContainer.Capacity = parentTable.RecordCache.CurrentCapacity; } if (column.AutoIncrement) { DataRowCollection rows = column.Table.Rows; for (int i = 0; i < rows.Count; i++) rows [i] [ordinal] = column.AutoIncrementValue (); } if (column.AutoIncrement) autoIncrement.Add(column); OnCollectionChanged (e); }
/// <summary> /// Creates and adds the specified DataColumn object to the DataColumnCollection. /// </summary> /// <param name="column">The DataColumn to add.</param> public void Add(DataColumn column) { if (column == null) { throw new ArgumentNullException("column", "'column' argument cannot be null."); } #if !NET_2_0 /* in 1.1, they must do this here, as the * setting of ColumnName below causes an event * to be raised */ column.PropertyChanged += new PropertyChangedEventHandler(ColumnPropertyChanged); #endif if (column.ColumnName.Length == 0) { column.ColumnName = GetNextDefaultColumnName(); } // if (Contains(column.ColumnName)) // throw new DuplicateNameException("A DataColumn named '" + column.ColumnName + "' already belongs to this DataTable."); if (column.Table != null) { throw new ArgumentException("Column '" + column.ColumnName + "' already belongs to this or another DataTable."); } column.SetTable(parentTable); RegisterName(column.ColumnName, column); int ordinal = base.List.Add(column); #if NET_2_0 column.Ordinal = ordinal; #else column.SetOrdinal(ordinal); #endif // Check if the Column Expression is ok if (column.CompiledExpression != null) { if (parentTable.Rows.Count == 0) { column.CompiledExpression.Eval(parentTable.NewRow()); } else { column.CompiledExpression.Eval(parentTable.Rows[0]); } } // if table already has rows we need to allocate space // in the column data container if (parentTable.Rows.Count > 0) { column.DataContainer.Capacity = parentTable.RecordCache.CurrentCapacity; } if (column.AutoIncrement) { DataRowCollection rows = column.Table.Rows; for (int i = 0; i < rows.Count; i++) { rows [i] [ordinal] = column.AutoIncrementValue(); } } if (column.AutoIncrement) { autoIncrement.Add(column); } #if NET_2_0 column.PropertyChanged += new PropertyChangedEventHandler(ColumnPropertyChanged); #endif OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, column)); }
/// <summary> /// Creates and adds the specified DataColumn object to the DataColumnCollection. /// </summary> /// <param name="column">The DataColumn to add.</param> public void Add (DataColumn column) { if (column == null) throw new ArgumentNullException ("column", "'column' argument cannot be null."); if (column.ColumnName.Length == 0) { column.ColumnName = GetNextDefaultColumnName (); } // if (Contains(column.ColumnName)) // throw new DuplicateNameException("A DataColumn named '" + column.ColumnName + "' already belongs to this DataTable."); if (column.Table != null) throw new ArgumentException ("Column '" + column.ColumnName + "' already belongs to this or another DataTable."); column.SetTable (parentTable); RegisterName (column.ColumnName, column); int ordinal = base.List.Add (column); column.Ordinal = ordinal; // Check if the Column Expression is ok if (column.CompiledExpression != null) if (parentTable.Rows.Count == 0) column.CompiledExpression.Eval (parentTable.NewRow()); else column.CompiledExpression.Eval (parentTable.Rows[0]); // if table already has rows we need to allocate space // in the column data container if (parentTable.Rows.Count > 0) column.DataContainer.Capacity = parentTable.RecordCache.CurrentCapacity; if (column.AutoIncrement) { DataRowCollection rows = column.Table.Rows; for (int i = 0; i < rows.Count; i++) rows [i] [ordinal] = column.AutoIncrementValue (); } if (column.AutoIncrement) autoIncrement.Add (column); column.PropertyChanged += new PropertyChangedEventHandler (ColumnPropertyChanged); OnCollectionChanged (new CollectionChangeEventArgs(CollectionChangeAction.Add, column)); }