Back to Devexpress

SpreadsheetCommandFactoryServiceWrapper.CreateCommand(SpreadsheetCommandId) Method

officefileapi-devexpress-dot-xtraspreadsheet-dot-services-dot-spreadsheetcommandfactoryservicewrapper-dot-createcommand-x28-devexpress-dot-xtraspreadsheet-dot-commands-dot-spreadsheetcommandid-x29.md

latest6.3 KB
Original Source

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.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public virtual SpreadsheetCommand CreateCommand(
    SpreadsheetCommandId id
)
vb
Public Overridable Function CreateCommand(
    id As SpreadsheetCommandId
) As SpreadsheetCommand

Parameters

NameTypeDescription
idDevExpress.XtraSpreadsheet.Commands.SpreadsheetCommandId

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

|

Returns

TypeDescription
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

csharp
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);
    }

}
vb
Public Class CustomService
    Inherits SpreadsheetCommandFactoryServiceWrapper

    Public Sub New(ByVal service As ISpreadsheetCommandFactoryService)
        MyBase.New(service)
    End Sub
    Public Property Control() As SpreadsheetControl

    Public Overrides Function CreateCommand(ByVal id As SpreadsheetCommandId) As SpreadsheetCommand
        If id = SpreadsheetCommandId.FormatClearContents OrElse id = SpreadsheetCommandId.FormatClearContentsContextMenuItem Then
            Return New CustomFormatClearContentsCommand(Control)
        End If

        Return MyBase.CreateCommand(id)
    End Function

End Class

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.

winforms-spreadsheet-replace-standard-command-with-custom-command/CS/SpreadsheetCustomCommand/CustomService.cs#L19

csharp
return base.CreateCommand(id);
}

wpf-spreadsheet-how-to-replace-standard-command-with-custom-command/CS/WpfSpreadsheet_CustomCommand/CustomCommandService.cs#L23

csharp
return new CustomFormatClearContentsCommand(Control);
    return base.CreateCommand(id);
}

winforms-spreadsheet-replace-standard-command-with-custom-command/VB/SpreadsheetCustomCommand/CustomService.vb#L20

vb
Return MyBase.CreateCommand(id)
End Function

wpf-spreadsheet-how-to-replace-standard-command-with-custom-command/VB/WpfSpreadsheet_CustomCommand/CustomCommandService.vb#L22

vb
End If
    Return MyBase.CreateCommand(id)
End Function

Implements

CreateCommand(SpreadsheetCommandId)

See Also

Services in WinForms Spreadsheet

How to: Replace Built-In Command with a Custom Command

SpreadsheetCommandFactoryServiceWrapper Class

SpreadsheetCommandFactoryServiceWrapper Members

DevExpress.XtraSpreadsheet.Services Namespace