Back to Devexpress

SpreadsheetControl.CustomCellEdit Event

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-4bcdc1f0.md

latest8.4 KB
Original Source

SpreadsheetControl.CustomCellEdit Event

Allows you to assign a custom in-place editor to a cell.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
public event SpreadsheetCustomCellEditEventHandler CustomCellEdit
vb
Public Event CustomCellEdit As SpreadsheetCustomCellEditEventHandler

Event Data

The CustomCellEdit event's data class is SpreadsheetCustomCellEditEventArgs. The following properties provide information specific to this event:

PropertyDescription
CellGets the cell for which the event is fired. Inherited from SpreadsheetCellEventArgsBase.
ColumnIndexGets the index of the column that contains the cell. Inherited from SpreadsheetCellEventArgsBase.
FormulaGets the formula that is currently contained in the cell. Inherited from SpreadsheetCellEventArgsBase.
FormulaInvariantGets the formula in the invariant culture that is currently contained in the cell. Inherited from SpreadsheetCellEventArgsBase.
RepositoryItemGets or sets the in-place editor for the current cell.
RowIndexGets the index of the row that contains the cell. Inherited from SpreadsheetCellEventArgsBase.
SheetNameGets the name of the worksheet that contains the cell. Inherited from SpreadsheetCellEventArgsBase.
ValueGets the value currently contained in the cell. Inherited from SpreadsheetCellEventArgsBase.
ValueObjectGets a value associated with the CustomCellInplaceEditor object assigned to the cell.
WorksheetGets the worksheet that contains the cell. Inherited from SpreadsheetCellEventArgsBase.

Remarks

The CustomCellEdit event fires each time an end user starts to edit a cell and allows you to replace the built-in cell editor with a custom one. The event’s Cell , ColumnIndex and RowIndex parameters help you identify the currently edited cell. To supply a custom editor to the cell, create a RepositoryItem descendant corresponding to the editor you want to use and assign it to the event’sDevExpress.XtraSpreadsheet.SpreadsheetCustomCellEditEventArgs.RepositoryItem parameter. Refer to the Editors and Simple Controls topic for additional information on this mechanism. The Included Controls and Components document lists available editors and their corresponding repository items.

The code snippet below shows how to assign a spin editor to the sixth column’s cells.

csharp
spreadsheetControl.CustomCellEdit += spreadsheetControl_CustomCellEdit;
// ...

//Create a repository item corresponding to a SpinEdit control
RepositoryItemSpinEdit repository = new RepositoryItemSpinEdit();
private void spreadsheetControl_CustomCellEdit(object sender, DevExpress.XtraSpreadsheet.SpreadsheetCustomCellEditEventArgs e)
{
    if (e.SheetName == "Sales report" && e.ColumnIndex == 5 && e.RowIndex > 1)
    {
        //specify the repository item settings.
        repository.AutoHeight = false;
        repository.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;

        repository.MinValue = 1;
        repository.MaxValue = 1000;
        repository.IsFloatValue = false;
        // Assign the spin editor to a cell.
        e.RepositoryItem = repository;
    }
}
vb
AddHandler spreadsheetControl.CustomCellEdit, AddressOf spreadsheetControl_CustomCellEdit
' ...

' Create a repository item corresponding to a SpinEdit control
Dim repository As New RepositoryItemSpinEdit()
Private Sub spreadsheetControl_CustomCellEdit(ByVal sender As Object, ByVal e As DevExpress.XtraSpreadsheet.SpreadsheetCustomCellEditEventArgs)
    If e.SheetName = "Sales report" AndAlso e.ColumnIndex = 5 AndAlso e.RowIndex > 1 Then
        ' Specify the repository item settings.
        repository.AutoHeight = False
        repository.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder

        repository.MinValue = 1
        repository.MaxValue = 1000
        repository.IsFloatValue = False
        ' Assign the spin editor to a cell.
        e.RepositoryItem = repository
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomCellEdit event.

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-assign-custom-in-place-editors/CS/Spreadsheet_CustomCellEditors/Form1.cs#L17

csharp
#region #CustomCellEdit
spreadsheetControl.CustomCellEdit += spreadsheetControl1_CustomCellEdit;
// ...

winforms-spreadsheet-assign-custom-in-place-editors/VB/Spreadsheet_CustomCellEditors/Form1.vb#L16

vb
#Region "#CustomCellEdit"
            AddHandler spreadsheetControl.CustomCellEdit, AddressOf spreadsheetControl1_CustomCellEdit
        ' ...

See Also

Custom Cell In-place Editors

How to: Save and Restore Custom Cell Editors

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace