Back to Devexpress

SpreadsheetCommandFactoryServiceWrapper Class

officefileapi-devexpress-dot-xtraspreadsheet-dot-services-54038f4e.md

latest3.6 KB
Original Source

SpreadsheetCommandFactoryServiceWrapper Class

A base class for implementing custom services used to substitute the default command factory service.

Namespace : DevExpress.XtraSpreadsheet.Services

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public class SpreadsheetCommandFactoryServiceWrapper :
    ISpreadsheetCommandFactoryService
vb
Public Class SpreadsheetCommandFactoryServiceWrapper
    Implements ISpreadsheetCommandFactoryService

Remarks

All commands in the SpreadsheetControl are created using the command factory service. You can substitute the default command factory service with its descendant designed to create a custom command instead of the default command. Subsequently, the specified custom command is used in all SpreadsheetControl operations instead of the replaced command.

The following code snippet demonstrates a custom service used to substitute the Clear Contents formatting commands located in Ribbon and context menu with a custom command.

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

Implements

ISpreadsheetCommandFactoryService

Inheritance

Object SpreadsheetCommandFactoryServiceWrapper

See Also

SpreadsheetCommandFactoryServiceWrapper Members

Services in WinForms Spreadsheet

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

DevExpress.XtraSpreadsheet.Services Namespace