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.v24.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);
    }

}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateCommand(SpreadsheetCommandId) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also