public void RemoveColumn(int index)
{
if (index < 0 || index > ColumnCount - 1)
throw new IndexOutOfRangeException();
foreach (Row r in Rows)
if (r.Cells.Count < ColumnCount)
{
var positionIndex = 0;
var actualPosition = 0;
var gridAfterVal = 0;
// checks to see if there is a deleted cell
gridAfterVal = r.gridAfter;
// goes through iteration of cells to find the one the that contains the index number
foreach (Cell rowCell in r.Cells)
{
// checks if the cell has a gridspan
var gridSpanVal = 0;
if (rowCell.GridSpan != 0)
{
gridSpanVal = rowCell.GridSpan - 1;
}
// checks to see if the index is within its lowest and highest cell value
if ((index - gridAfterVal) >= actualPosition
&& (index - gridAfterVal) <= (actualPosition + gridSpanVal))
{
r.Cells[positionIndex].Xml.Remove();
break;
}
positionIndex += 1;
actualPosition += gridSpanVal + 1;
}
}
else
{
r.Cells[index].Xml.Remove();
}
_cachedColCount = -1;
}