/// <summary> /// insert rows into table control /// </summary> /// <param name="rowStart">the index at which to begin insert</param> /// <param name="rowsToInsert">number of rows to be inserted</param> internal override void InsertRows(int rowStart, int rowsToInsert, bool manipulateEditors) { if (rowStart < 0 || rowsToInsert <= 0) { return; } _mgCount += rowsToInsert; for (int idx = rowStart; idx < rowStart + rowsToInsert; idx++) { _tableControl.InsertItem(getGuiRowIndex(rowStart)); } if (manipulateEditors) { // if allowTesting, do not perform insert, use shiftrows instead. if (GuiUtils.AccessTest) { ShiftEditors(rowStart, rowsToInsert); } else { InsertEditorsForVisibleColumns(rowStart, rowsToInsert); } } // move rows after rowStart in controlsMap for (int i = 0; i < _children.Count; i++) { if (!_children[i].IsTableHeaderChild) { ArrayList arrayControl = controlsMap.object2WidgetArray(_children[i], GuiConstants.ALL_LINES); if (arrayControl == null) { break; } if (rowStart <= arrayControl.Count) { for (int idx = rowStart; idx < rowStart + rowsToInsert; idx++) { arrayControl.Insert(rowStart, null); } } for (int j = rowStart + rowsToInsert; j < arrayControl.Count; j++) { LogicalControl lg = (LogicalControl)arrayControl[j] ?? null; if (lg != null) { lg._mgRow = j; ((TableCoordinator)lg.Coordinator).MgRow = j; TableEditor editor = getTableEditor(lg); // reapply properties on the editor if (editor != null && editor.Control != null) { TagData tagData = (TagData)(((Control)editor.Control).Tag); if (tagData.MapData is MapData) { MapData mapData = (MapData)tagData.MapData; int row = mapData.getIdx(); row = j; mapData.setIdx(row); } } } } } } }
/// <summary> /// remove rows from table control /// </summary> /// <param name="rowStart">the index at which to begin remove</param> /// <param name="rowsToRemove">number of rows to remove</param> internal override void RemoveRows(int rowStart, int rowsToRemove, bool manipulateEditors) { int numOfRows = _tableControl.getItemsCount(); if (rowStart < 0 || rowStart >= numOfRows && rowsToRemove <= 0) { return; } if (rowStart + rowsToRemove > numOfRows) { rowsToRemove = numOfRows - rowStart; } _mgCount -= rowsToRemove; for (int idx = rowStart; idx < rowStart + rowsToRemove; idx++) { _tableControl.RemoveItem(getGuiRowIndex(rowStart)); } if (manipulateEditors) { // if allowTesting, do not perform remove, use shiftrows instead. if (GuiUtils.AccessTest) { ShiftEditors(rowStart, -rowsToRemove); } else { RemoveEditorsForVisibleColumns(rowStart, rowsToRemove); } } // update controlsMap for (int i = 0; i < _children.Count; i++) { if (!_children[i].IsTableHeaderChild) { ArrayList arrayControl = controlsMap.object2WidgetArray(_children[i], GuiConstants.ALL_LINES); // lg.Dispose() can remove entries from controlsMap and hence arrayControl can be null. // In that case no need to continue even for other columns in same row. if (arrayControl == null) { break; } for (int idx = 0; idx < rowsToRemove && rowStart < arrayControl.Count; idx++) { long entriesBeforeDispose = arrayControl.Count; LogicalControl lg = (LogicalControl)arrayControl[rowStart] ?? null; if (lg != null) { // As we delete entries from arrayControl, we should adjust _mgRow in // logical controls. _mgRow is used as index to remove Control from map lg._mgRow = rowStart; lg.Dispose(); } // LogicalControl.Dispose removes entry from the map only all entries after current // entry are null. If Dispose has not removed the entry, then remove it. if (entriesBeforeDispose == arrayControl.Count) { arrayControl.RemoveAt(rowStart); } } for (int j = rowStart; j < arrayControl.Count; j++) { LogicalControl lg = (LogicalControl)arrayControl[j] ?? null; if (lg != null) { lg._mgRow = j; ((TableCoordinator)lg.Coordinator).MgRow = j; TableEditor editor = getTableEditor(lg); // reapply properties on the editor if (editor != null && editor.Control != null) { TagData tagData = (TagData)(((Control)editor.Control).Tag); if (tagData.MapData is MapData) { MapData mapData = (MapData)tagData.MapData; int row = mapData.getIdx(); row = j; mapData.setIdx(row); } } } } } } // remove from _rowsToRefresh for (int idx = rowStart; idx < rowStart + rowsToRemove; idx++) { if (_rowsToRefresh.Contains(getGuiRowIndex(rowStart))) { _rowsToRefresh.Remove(getGuiRowIndex(rowStart)); } } }