/// <summary> /// Copies the data of the column (columns have same type, index is inside bounds), or replaces /// the column (columns of different types, index inside bounds), or adds the column (index outside bounds). /// </summary> /// <param name="index">The column position where to replace or add.</param> /// <param name="datac">The column from which the data should be copied or which should replace the existing column or which should be added.</param> /// <param name="name">The name under which the column should be stored.</param> public void CopyOrReplaceOrAdd(int index, DataColumn datac, string name) { if(index<ColumnCount) { if(this[index].GetType().Equals(datac.GetType())) { this[index].CopyDataFrom(datac); } else { // if the column to add has a parent, we can not add the column directly (we are then not the owner), so we clone it Replace(index,datac.ParentObject==null ? datac : (DataColumn)datac.Clone()); } } else { // if the column to add has a parent, we can not add the column directly (we are then not the owner), so we clone it Add(datac.ParentObject==null ? datac : (DataColumn)datac.Clone(), name); } }