Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Cells / Managing Data on a Sheet / Moving Data on a Sheet
In This Topic
    Moving Data on a Sheet
    In This Topic

    You can move data from one cell or range of cells to another using the Move methods for the sheet.

    When you move data from one cell (or range of cells) to another, the data from the origination cell (or range of cells) replaces the data in the destination cell (or cells). If the operation moves a range of cells to an overlapping location, the values of all the cells of the range are replaced with the values of the cells in the moved range.

    You can specify whether formulas are automatically updated when cells or ranges of cells are moved. For more information on automatic recalculation, refer to Recalculating and Updating Formulas Automatically.

    To move data 3 rows up the sheet and 5 rows down, you would need to insert blank rows where you want to move the rows to. To move 3 rows up and 5 rows down, copy the five rows temporarily then move the 3 rows up to their positions and then assign the five copied rows to the correct position.

    Example

    This example moves data in the sheet and inserts blank rows.

    C#
    Copy Code
    fpSpread1.Sheets[0].SetText(6, 0, "test");
    var with1 = (FarPoint.Win.Spread.Model.DefaultSheetDataModel)fpSpread1.Sheets[0].Models.Data;
    FarPoint.Win.Spread.Model.DefaultSheetDataModel dm = new FarPoint.Win.Spread.Model.DefaultSheetDataModel(5, with1.ColumnCount);
    dm.SetArray(0, 0, ((FarPoint.Win.Spread.Model.DefaultSheetDataModel)fpSpread1.Sheets[0].Models.Data).GetArray(0, 0, 5, 5));
    with1.RemoveRows(0, 5);
    with1.AddRows(0, 3);
    with1.Move(with1.RowCount - 4, 0, 0, 0, 3, with1.ColumnCount);
    with1.RemoveRows(with1.RowCount - 4, 3);
    with1.AddRows(with1.RowCount, 5);
    with1.SetArray(with1.RowCount - 6, 0, dm.GetArray(0, 0, 5, with1.ColumnCount));
    
    VB
    Copy Code
    fpSpread1.Sheets(0).SetText(6, 0, "test")
    With CType(fpSpread1.Sheets(0).Models.Data, FarPoint.Win.Spread.Model.DefaultSheetDataModel)
    Dim dm As New FarPoint.Win.Spread.Model.DefaultSheetDataModel(5, .ColumnCount)
    dm.SetArray(0, 0, CType(fpSpread1.Sheets(0).Models.Data, FarPoint.Win.Spread.Model.DefaultSheetDataModel).GetArray(0, 0, 5, 5))
    .RemoveRows(0, 5)
    .AddRows(0, 3)
    .Move(.RowCount - 4, 0, 0, 0, 3, .ColumnCount)
    .RemoveRows(.RowCount - 4, 3)
    .AddRows(.RowCount, 5)
    .SetArray(.RowCount - 6, 0, dm.GetArray(0, 0, 5, .ColumnCount))
    End With
    
    See Also