Skip to main content

How to: Save and Restore Custom Cell Editors

  • 3 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.


A complete sample project is available in the DevExpress-Examples/how-to-assign-custom-in-place-editors-to-worksheet-cells-t385401 repository on GitHub.

  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;
    // ...
    // Create a repository item corresponding to a SpinEdit control
    RepositoryItemSpinEdit repository = new RepositoryItemSpinEdit();
    private void spreadsheetControl_CustomCellEdit(object sender, DevExpress.XtraSpreadsheet.SpreadsheetCustomCellEditEventArgs e)
        // Specify the 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")
            //Specify the repository item settings.
            repository.AutoHeight = false;
            repository.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
            repository.MinValue = 1;
            repository.MaxValue = 1000;
            repository.IsFloatValue = false;
            // Assign the SpinEdit editor to a cell.
            e.RepositoryItem = repository;
See Also