windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-dot-closecelleditor-x28-devexpress-dot-xtraspreadsheet-dot-celleditorentervaluemode-x29.md
Closes the cell editor.
Namespace : DevExpress.XtraSpreadsheet
Assembly : DevExpress.XtraSpreadsheet.v25.2.dll
NuGet Package : DevExpress.Win.Spreadsheet
public bool CloseCellEditor(
CellEditorEnterValueMode mode
)
Public Function CloseCellEditor(
mode As CellEditorEnterValueMode
) As Boolean
| Name | Type | Description |
|---|---|---|
| mode | CellEditorEnterValueMode |
A CellEditorEnterValueMode enumeration member.
|
| Type | Description |
|---|---|
| Boolean |
true if the cell editor is closed successfully; otherwise, false.
|
Use the CloseCellEditor method to close an open cell editor. To check whether a cell editor is currently active, use the SpreadsheetControl.IsCellEditorActive property. The CloseCellEditor method’s parameter specifies whether to commit an entered value to a cell or roll it back when the editor is closed.
|
Parameter
|
Description
|
Shortcut
|
Related Events
| | --- | --- | --- | --- | |
CellEditorEnterValueMode.ActiveCell
|
Commits an entered value to an active cell.
|
ENTER
|
SpreadsheetControl.CellEndEdit
SpreadsheetControl.CellValueChanged
| |
CellEditorEnterValueMode.SelectedCells
|
Commits an entered value to all selected cells.
|
CTRL+ENTER
|
SpreadsheetControl.CellEndEdit
SpreadsheetControl.CellValueChanged
| |
CellEditorEnterValueMode.ArrayFormula
|
Commits an entered formula to an active cell or selected cells as an array formula.
|
CTRL+SHIFT+ENTER
|
SpreadsheetControl.CellEndEdit
SpreadsheetControl.CellValueChanged
| |
CellEditorEnterValueMode.Cancel
|
Cancels an entry in the cell editor.
|
ESC
|
SpreadsheetControl.CellCancelEdit
|
You can specify when the SpreadsheetControl.CellValueChanged event should occur after a cell value was edited and committed to a cell: each time, or only if a cell value was changed. To do this, use the SpreadsheetControl.Options.Behavior.CellEditor.CommitMode property (SpreadsheetCellEditorBehaviorOptions.CommitMode).
The following example shows how to use the CloseCellEditor method to commit changes in the active cell editor before the application is closed and save a document.
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (spreadsheetControl1.IsCellEditorActive)
spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.ActiveCell);
if (spreadsheetControl1.Modified)
spreadsheetControl1.SaveDocument();
}
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
If spreadsheetControl1.IsCellEditorActive Then
spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.ActiveCell)
End If
If spreadsheetControl1.Modified Then
spreadsheetControl1.SaveDocument()
End If
End Sub
The following code snippets (auto-collected from DevExpress Examples) contain references to the CloseCellEditor(CellEditorEnterValueMode) 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-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L160
if (spreadsheetControl1.IsCellEditorActive)
spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.Cancel);
sheet.Rows.Remove(sheet.SelectedCell.TopRowIndex, 1);
if (control != null && control.IsCellEditorActive)
control.CloseCellEditor(mode);
}
winforms-spreadsheet-bind-to-ms-sql-server-database/CS/SuppliersExample/Form1.cs#L149
if (spreadsheetControl1.IsCellEditorActive)
spreadsheetControl1.CloseCellEditor(DevExpress.XtraSpreadsheet.CellEditorEnterValueMode.Default);
}
winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L148
If Equals(sheet.Name, "Invoice") Then
If spreadsheetControl1.IsCellEditorActive Then spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.Cancel)
sheet.Rows.Remove(sheet.SelectedCell.TopRowIndex, 1)
If _control IsNot Nothing AndAlso _control.IsCellEditorActive Then
_control.CloseCellEditor(mode)
End If
winforms-spreadsheet-bind-to-ms-sql-server-database/VB/SuppliersExample/Form1.vb#L143
Private Sub CloseInplaceEditor()
If spreadsheetControl1.IsCellEditorActive Then spreadsheetControl1.CloseCellEditor(DevExpress.XtraSpreadsheet.CellEditorEnterValueMode.Default)
End Sub
See Also