SourceGrid.RangeData.WriteData C# (CSharp) Method

WriteData() public method

Write the current loaded array string in the specified grid range. This method use the cell editor to set the value.
public WriteData ( GridVirtual destinationGrid, Range destinationRange ) : void
destinationGrid GridVirtual
destinationRange Range
return void
        public void WriteData(GridVirtual destinationGrid, Range destinationRange)
        {
            //Calculate the destination Range merging the source range
            Range newRange = mSourceRange;
            newRange.MoveTo(destinationRange.Start);
            if (newRange.ColumnsCount > destinationRange.ColumnsCount)
                newRange.ColumnsCount = destinationRange.ColumnsCount;
            if (newRange.RowsCount > destinationRange.RowsCount)
                newRange.RowsCount = destinationRange.RowsCount;

            //Cut Data
            if (CutMode == CutMode.CutOnPaste && mSourceGrid != null)
            {
                for (int sr = mSourceRange.Start.Row; sr <= mSourceRange.End.Row; sr++)
                    for (int sc = mSourceRange.Start.Column; sc <= mSourceRange.End.Column; sc++)
                    {
                        Position pos = new Position(sr, sc);
                        Cells.ICellVirtual cell = mSourceGrid.GetCell(sr, sc);
                        CellContext cellContext = new CellContext(mSourceGrid, pos, cell);
                        if (cell.Editor != null)
                            cell.Editor.ClearCell(cellContext);
                    }
            }

            int arrayRow = 0;
            for (int r = newRange.Start.Row; r <= newRange.End.Row; r++, arrayRow++)
            {
                int arrayCol = 0;
                for (int c = newRange.Start.Column; c <= newRange.End.Column; c++, arrayCol++)
                {
                    Position posCell = new Position(r, c);
                    Cells.ICellVirtual cell = destinationGrid.GetCell(posCell);
                    CellContext cellContext = new CellContext(destinationGrid, posCell, cell);

                    if (cell != null && cell.Editor != null && mSourceValues[arrayRow, arrayCol] != null)
                        cell.Editor.SetCellValue(cellContext, mSourceValues[arrayRow, arrayCol] );
                }
            }
        }