windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-4bcdc1f0.md
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
public event SpreadsheetCustomCellEditEventHandler CustomCellEdit
Public Event CustomCellEdit As SpreadsheetCustomCellEditEventHandler
The CustomCellEdit event's data class is SpreadsheetCustomCellEditEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Cell | Gets the cell for which the event is fired. Inherited from SpreadsheetCellEventArgsBase. |
| ColumnIndex | Gets the index of the column that contains the cell. Inherited from SpreadsheetCellEventArgsBase. |
| Formula | Gets the formula that is currently contained in the cell. Inherited from SpreadsheetCellEventArgsBase. |
| FormulaInvariant | Gets the formula in the invariant culture that is currently contained in the cell. Inherited from SpreadsheetCellEventArgsBase. |
| RepositoryItem | Gets or sets the in-place editor for the current cell. |
| RowIndex | Gets the index of the row that contains the cell. Inherited from SpreadsheetCellEventArgsBase. |
| SheetName | Gets the name of the worksheet that contains the cell. Inherited from SpreadsheetCellEventArgsBase. |
| Value | Gets the value currently contained in the cell. Inherited from SpreadsheetCellEventArgsBase. |
| ValueObject | Gets a value associated with the CustomCellInplaceEditor object assigned to the cell. |
| Worksheet | Gets the worksheet that contains the cell. Inherited from SpreadsheetCellEventArgsBase. |
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.
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;
}
}
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
#region #CustomCellEdit
spreadsheetControl.CustomCellEdit += spreadsheetControl1_CustomCellEdit;
// ...
winforms-spreadsheet-assign-custom-in-place-editors/VB/Spreadsheet_CustomCellEditors/Form1.vb#L16
#Region "#CustomCellEdit"
AddHandler spreadsheetControl.CustomCellEdit, AddressOf spreadsheetControl1_CustomCellEdit
' ...
See Also