public void TenEmptyColumns() { DataColumnCollection d = new DataColumnCollection(); DataColumn[] cols = new DataColumn[10]; for (int i = 0; i < 10; i++) { cols[i] = new DoubleColumn(); d.Add(cols[i]); } Assert.AreEqual(10, d.ColumnCount); Assert.AreEqual(0, d.RowCount); Assert.AreEqual(false, d.IsDirty); Assert.AreEqual(false, d.IsSuspended); Assert.AreEqual("A", d.GetColumnName(0)); Assert.AreEqual("A", d[0].Name); Assert.AreEqual("J", d.GetColumnName(9)); Assert.AreEqual("J", d[9].Name); // Test index to column resolution for (int i = 0; i < 10; i++) { Assert.AreEqual(cols[i], d[i]); } // test name to column resolution for (int i = 0; i < 10; i++) { char name = (char)('A' + i); Assert.AreEqual(cols[i], d[name.ToString()], "Column to name resolution of col " + name.ToString()); } // test column to number resolution for (int i = 0; i < 10; i++) { Assert.AreEqual(i, d.GetColumnNumber(cols[i])); } }
/// <summary> /// Copies one row of a <see cref="DataColumnCollection"/> to another row in the same or in another <see cref="DataColumnCollection"/>. The columns in the source collection are mapped to the columns in /// the destination collection by name; if a column does not exist in the destination collection, this source column is silently ignored and therefore is not copied. /// </summary> /// <param name="sourceTable">The source <see cref="DataColumnCollection"/>.</param> /// <param name="sourceRowIndex">Index of the source row.</param> /// <param name="selectedSourceDataColumns">The selected source data columns. If this parameter is null, all source columns are selected for copying.</param> /// <param name="destinationTable">The destination <see cref="DataColumnCollection"/>.</param> /// <param name="destinationRowIndex">Index of the destination row.</param> public static void CopyRowToRowByColumnName(this DataColumnCollection sourceTable, int sourceRowIndex, IAscendingIntegerCollection selectedSourceDataColumns, DataColumnCollection destinationTable, int destinationRowIndex) { if (null == selectedSourceDataColumns || 0 == selectedSourceDataColumns.Count) { selectedSourceDataColumns = Altaxo.Collections.ContiguousIntegerRange.FromStartAndCount(0, sourceTable.ColumnCount); } foreach (var colIdx in selectedSourceDataColumns) { var srcColName = sourceTable.GetColumnName(colIdx); if (!destinationTable.Contains(srcColName)) { continue; } destinationTable[srcColName][destinationRowIndex] = sourceTable[srcColName][sourceRowIndex]; } }
/// <summary> /// Ensures that the selected columns in the source <see cref="DataColumnCollection"/> do also exist in the destination <see cref="DataColumnCollection"/>. /// </summary> /// <param name="sourceTable">The source table.</param> /// <param name="selectedSourceDataColumns">The selected source data columns. If this parameter is null, all source columns are selected.</param> /// <param name="destinationTable">The destination table.</param> public static void EnsureColumnsExistInDestinationCollection(this DataColumnCollection sourceTable, IAscendingIntegerCollection selectedSourceDataColumns, DataColumnCollection destinationTable) { if (null == selectedSourceDataColumns || 0 == selectedSourceDataColumns.Count) { selectedSourceDataColumns = Altaxo.Collections.ContiguousIntegerRange.FromStartAndCount(0, sourceTable.ColumnCount); } foreach (var colIdx in selectedSourceDataColumns) { var srcCol = sourceTable[colIdx]; destinationTable.EnsureExistence( sourceTable.GetColumnName(srcCol), srcCol.GetType(), sourceTable.GetColumnKind(srcCol), sourceTable.GetColumnGroup(srcCol) ); } }
protected override void LoadChildren() { DataColumnCollection coll = _collection; Nodes.Clear(); int nextColumn = Math.Min(_firstColumn + _columnCount, coll.ColumnCount); if (_columnCount <= MaxNumberOfColumnsInOneNode) // If number is low enough, expand to the data columns directly { for (int i = _firstColumn; i < nextColumn; ++i) { Nodes.Add(new NGTreeNode() { Text = coll.GetColumnName(i), Tag = coll[i] }); } } else // if the number of data columns is too high to be directly shown, we create intermediate nodes { // calculate the number of nodes to be shown int numNodes = (int)Math.Ceiling(_columnCount / (double)MaxNumberOfColumnsInOneNode); numNodes = Math.Min(MaxNumberOfColumnsInOneNode, numNodes); int colsInOneNode = MaxNumberOfColumnsInOneNode; for (; colsInOneNode *numNodes < _columnCount; colsInOneNode *= MaxNumberOfColumnsInOneNode) { ; // Multiply with a multiple of MaxNumberOfColumnsInOneNode until it fits } int first = _firstColumn; int remaining = nextColumn - _firstColumn; for (int i = 0; i < numNodes && remaining > 0; ++i) { Nodes.Add(new TableNode(coll, first, Math.Min(remaining, colsInOneNode))); remaining -= colsInOneNode; first += colsInOneNode; } } }