Articles in this section
Category / Section

How to obtain old and new value of the cells while performing drag fill operation in WPF Spreadsheet?

2 mins read

You have to create a new class which is derived from FillSeriesController and override the FillSeries & CopyCells methods to get the old and new value of the cells while performing drag and fill operation.

FillSeries method is invoked when the cell values are filled in a series after dragging and CopyCells method is invoked when the cell values are copied after dragging. On both methods, you can get the filled range from the argument “newRange”. Get the old value of the cells before calling the base method and get the new value of the cells after calling the base method like below code example.

 

protected override void FillSeries(GridRangeInfo oldRange, GridRangeInfo newRange)
{
    //You can get the old values of each cell by looping the excelRange.Row, excelRange.Column, excelRange.LastRow and excelRange.LastColumn
    var excelRangeString = newRange.ConvertGridRangeToExcelRange(grid);
    var excelRange = Worksheet[excelRangeString];
 
    base.FillSeries(oldRange, newRange);
 
    //You can get the new values (after fill) of each cell by looping the excelRange.
    excelRangeString = newRange.ConvertGridRangeToExcelRange(grid);
    excelRange = Worksheet[excelRangeString];
}
 
protected override void CopyCells(GridRangeInfo oldRange, GridRangeInfo newRange)
{
    //You can get the old values of each cell by looping the excelRange.Row, excelRange.Column, excelRange.LastRow and excelRange.LastColumn
    var excelRangeString = newRange.ConvertGridRangeToExcelRange(grid);
    var excelRange = Worksheet[excelRangeString];
 
    base.CopyCells(oldRange, newRange);
 
    //You can get the new values (after fill) of each cell by looping the excelRange.
    excelRangeString = newRange.ConvertGridRangeToExcelRange(grid);
    excelRange = Worksheet[excelRangeString];
}

 

Then assign the instance of that custom FillSeriesController to the FillSeriesController property of each SpreadsheetGrid in the WorkbookLoaded and WorksheetAdded event of Spreadsheet.

 

C#

spreadsheet.WorkbookLoaded += spreadsheet_WorkbookLoaded;
spreadsheet.WorksheetAdded += spreadsheet_WorksheetAdded;
 
void spreadsheet_WorksheetAdded(object sender, WorksheetAddedEventArgs args)
{
    var grid = spreadsheet.ActiveGrid;
    grid.FillSeriesController = new FillSeriesControllerExt(grid);
}
 
void spreadsheet_WorkbookLoaded(object sender, WorkbookLoadedEventArgs args)
{
    foreach (var grid in args.GridCollection)
    {
        grid.FillSeriesController = new FillSeriesControllerExt(grid);
    }
}

 

Sample Link:

WPF

UWP

 

Conclusion

I hope you enjoyed learning about how to obtain old and new value of the cells while performing drag fill operation in WPF Spreadsheet.

You can refer to our WPF Spreadsheet feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Spreadsheet documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied