Skip to main content

How to: Save and Restore Custom Cell Editors

  • 2 minutes to read

The SpreadsheetControl can save information about custom in-place editors to a file in XLS, XLSX, XLSB, XLT, and XLTX formats. This allows the SpreadsheetControl to restore custom editors when you load a document into the control again.

Custom editors from the predefined set are saved and restored automatically.

To save an editor supplied to cells via the SpreadsheetControl.CustomCellEdit event, use the following approach.

View Example

  1. Use the CustomCellInplaceEditorCollection.Add method to assign an editor of CustomCellInplaceEditorType.Custom type to a cell range and specify the textual value associated with this custom editor. The SpreadsheetControl saves the specified string to a file and then uses it to restore the editor.

    // Specify that cells located in the "Quantity" table column contain a custom editor "MySpinEdit".
    CellRange customRange = worksheet["Table[Quantity]"];
    worksheet.CustomCellInplaceEditors.Add(customRange, CustomCellInplaceEditorType.Custom, "MySpinEdit");
  2. Handle the SpreadsheetControl.CustomCellEdit event to assign an editor (SpinEdit) to cells that are marked as containing the custom editor (“MySpinEdit”). To identify these cells, use the event’s SpreadsheetCustomCellEditEventArgs.ValueObject parameter.

    spreadsheetControl.CustomCellEdit += spreadsheetControl_CustomCellEdit;
    // ...
    private void spreadsheetControl_CustomCellEdit(object sender, SpreadsheetCustomCellEditEventArgs e)
        // Specify a type of the custom editor assigned to cells of the "Quantity" table column.
        // To identify the custom editor, use a value of ValueObject associated with it.
        if (e.ValueObject.IsText && e.ValueObject.TextValue == "MySpinEdit")
            // Create a SpinEdit in-place editor and assign it to a cell.
            SpinEditSettings settings = new SpinEditSettings();
            settings.MinValue = 1;
            settings.MaxValue = 1000;
            settings.IsFloatValue = false;
            e.EditSettings = settings;
See Also