officefileapi-devexpress-dot-xtraspreadsheet-dot-services-dot-spreadsheetcommandfactoryservicewrapper-dot-createcommand-x28-devexpress-dot-xtraspreadsheet-dot-commands-dot-spreadsheetcommandid-x29.md
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
public virtual SpreadsheetCommand CreateCommand(
SpreadsheetCommandId id
)
Public Overridable Function CreateCommand(
id As SpreadsheetCommandId
) As SpreadsheetCommand
| Name | Type | Description |
|---|---|---|
| id | DevExpress.XtraSpreadsheet.Commands.SpreadsheetCommandId |
A DevExpress.XtraSpreadsheet.Commands.SpreadsheetCommandId member specifying a command to create.
|
| Type | Description |
|---|---|
| DevExpress.XtraSpreadsheet.Commands.SpreadsheetCommand |
A Spreadsheet command object.
|
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.
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);
}
}
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.
return base.CreateCommand(id);
}
return new CustomFormatClearContentsCommand(Control);
return base.CreateCommand(id);
}
Return MyBase.CreateCommand(id)
End Function
End If
Return MyBase.CreateCommand(id)
End Function
CreateCommand(SpreadsheetCommandId)
See Also
Services in WinForms Spreadsheet
How to: Replace Built-In Command with a Custom Command
SpreadsheetCommandFactoryServiceWrapper Class