//Insert new column after other columns void InsertColumnSimple(string columnName) { //Make room for new column and set it's name Array.Resize<string>(ref columnNames, columnNames.Length + 1); columnNames[columnNames.Length - 1] = columnName; //Make room for the new column's values in old rows for(int i = 0; i < rows.Count; i++) { Array.Resize<VDB_Value>(ref rows[i].values, rows[i].values.Length + 1); VDB_Value newValue = new VDB_Value(); newValue.SetNull(); rows[i].values[rows[i].values.Length - 1] = newValue; } }
//Insert new column after the given one void InsertColumnComplex(string columnName, string afterColumn) { int afterColumnNumber = GetColumnNumberFromName(afterColumn); //Cast columnNames array to list to insert a new value in the middle of it List<string> tempColumnList = new List<string>(); tempColumnList.AddRange(columnNames); tempColumnList.Insert(afterColumnNumber + 1, columnName); //Then cast it back columnNames = tempColumnList.ToArray(); //Then do the same with all the values in rows for (int i = 0; i < rows.Count; i++) { VDB_TableRow row = rows[i]; List<VDB_Value> tempRowValues = new List<VDB_Value>(); tempRowValues.AddRange(row.values); VDB_Value newValue = new VDB_Value(); newValue.SetNull(); tempRowValues.Insert(afterColumnNumber + 1, newValue); row.values = tempRowValues.ToArray(); } }