Interactive Features in UWP Spreadsheet (SfSpreadsheet)
23 Jul 20264 minutes to read
This section explains about the interactive operations with SfSpreadsheet
Clipboard Operations
SfSpreadsheet provides support for all the clipboard operations with all the format settings when copied within a workbook.
You can use the following shortcut keys for Clipboard operations like Excel
| Operations | Shortcut Keys |
|---|---|
| Cut | Ctrl + X |
| Copy | Ctrl + C |
| Paste | Ctrl + V |
The following are a list of paste options used while performing paste operation,
| Options | Description |
|---|---|
| Paste | To paste with all the format options in the source range |
| Formula | To paste the formulas alone |
| Keep Source Formatting | To maintain the source range’s formatting |
| Value | To paste the values alone |
| Format | To paste only the formats alone without pasting the values. |
| Value & Source Formatting | To maintain the source range original format and paste only values |
NOTE
When the content is copied from an external source, SfSpreadsheet does not support the format settings (paste options).
For Cut Operation,
//To perform cut operation for selected ranges
var range = spreadsheet.ActiveGrid.SelectedRanges.ActiveRange;
spreadsheet.ActiveGrid.CopyPaste.Copy(range, true);
//To perform cut operation
spreadsheet.ActiveGrid.CopyPaste.Cut();For Copy Operation,
//To perform copy operation for selected ranges
var range = spreadsheet.ActiveGrid.SelectedRanges.ActiveRange;
spreadsheet.ActiveGrid.CopyPaste.Copy(range, false);
//To perform Copy operation
spreadsheet.ActiveGrid.CopyPaste.Copy();For Paste Operation,
//To perform paste operation
spreadsheet.ActiveGrid.CopyPaste.Paste();
//To perform paste operation with range and PasteOptions
var copyPaste = spreadsheet.ActiveGrid.CopyPaste as SpreadsheetCopyPaste;
copyPaste.Paste(range);
copyPaste.Paste(range, PasteOptions.Paste);TIPS
Users can also set their default
PasteOptionswhile pasting in SfSpreadsheet, by usingDefaultPasteOptionProperty.
Undo/Redo
SfSpreadsheet provides support for Undo/Redo functionality like Microsoft Excel.
The shortcut keys used for Undo/Redo Operations
| Operations | Shortcut Keys |
|---|---|
| Undo | Ctrl + Z |
| Redo | Ctrl + Y |
SfSpreadsheet has History Manager class that supports the implementation of undo/redo operations.
By default, Undo/Redo operations in SfSpreadsheet is enabled. To disable the Undo/Redo operations, set the Enabled property of History Manager to false.
spreadsheet.HistoryManager.Enabled = false;To programmatically invoke the Undo/Redo operations,
spreadsheet.HistoryManager.Enabled = true;
spreadsheet.HistoryManager.Undo();
spreadsheet.HistoryManager.Redo();Context Menu
Context Menu in SfSpreadsheet is a customizable menu that can be used for various functionalities.
Cell Context Menu
Cell Context Menu opens when the user right-clicks on a worksheet cell or selection of cells in SfSpreadsheet.
By default, Cell Context Menu is enabled in SfSpreadsheet. To disable the Cell Context Menu, set the AllowCellContextMenu property to false.
spreadsheet.AllowCellContextMenu = false;Users can also customize the Cell Context menu of SfSpreadsheet by using CellContextMenuOpening Event of SpreadsheetGrid.
Adding the customized menu items in the CellContextMenuOpening Event,
spreadsheet.ActiveGrid.CellContextMenuOpening += ActiveGrid_CellContextMenuOpening;
void ActiveGrid_CellContextMenuOpening(object sender, CellContextMenuOpeningEventArgs e)
{
//Adding Customized Menu item
MenuItem PasteSpecial = new MenuItem();
PasteSpecial.Header = "PasteSpecial";
Image paste = new Image() { Source = new BitmapImage(new Uri(@"..\..\Icon\paste.png", UriKind.Relative)) };
PasteSpecial.Icon = paste;
spreadsheet.ActiveGrid.CellContextMenu.Items.Add(PasteSpecial);
//Remove the existing Context menu
spreadsheet.ActiveGrid.CellContextMenu.Items.RemoveAt(2);
}TIPS
Custom Cell Context Menu can also be added by assigning the customized menu items to the
CellContextMenuproperty ofSpreadsheetGrid. For your reference, CustomContextMenu
Cell Comments
SfSpreadsheet provides support for cell comments like in Excel to give the reader additional context for the data it contains. You can set the comment’s height and color at runtime in the CellCommentOpening event of SpreadsheetGrid.
To enable the comment in SfSpreadsheet, set the ShowComment property of SpreadsheetGrid to true.
spreadsheet.ActiveGrid.ShowComment = true;To set the comments for particular cell at run time,
spreadsheet.ActiveSheet.Range["E5"].AddComment().Text = "Sample Comment";
spreadsheet.ActiveGrid.InvalidateCell(5, 5);