Skip to main content

SpreadsheetCommandFactoryServiceWrapper.CreateCommand(SpreadsheetCommandId) Method

Override the method in the SpreadsheetCommandFactoryServiceWrapper descendant to create a custom command for the specific ID.

Namespace: DevExpress.XtraSpreadsheet.Services

Assembly: DevExpress.Spreadsheet.v26.1.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

public virtual SpreadsheetCommand CreateCommand(
    SpreadsheetCommandId id
)

Parameters

Name Type Description
id DevExpress.XtraSpreadsheet.Commands.SpreadsheetCommandId

A DevExpress.XtraSpreadsheet.Commands.SpreadsheetCommandId member specifying a command to create.

Returns

Type Description
DevExpress.XtraSpreadsheet.Commands.SpreadsheetCommand

A Spreadsheet command object.

Remarks

The following code snippet illustrates a custom service inherited from the SpreadsheetCommandFactoryServiceWrapper service with the CreateCommand method overridden. It creates a custom command instead of the Clear Contents formatting commands located in Ribbon and context menu.

View Example

public class CustomService : SpreadsheetCommandFactoryServiceWrapper {
    public CustomService(ISpreadsheetCommandFactoryService service)
        : base(service) {
    }
    public SpreadsheetControl Control {get;set;}

    public override SpreadsheetCommand CreateCommand(SpreadsheetCommandId id)
    {
        if (id == SpreadsheetCommandId.FormatClearContents || id == SpreadsheetCommandId.FormatClearContentsContextMenuItem)
            return new CustomFormatClearContentsCommand(Control);

        return base.CreateCommand(id);
    }

}
See Also