Back to Devexpress

SpreadsheetControl.CloseCellEditor(CellEditorEnterValueMode) Method

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-dot-closecelleditor-x28-devexpress-dot-xtraspreadsheet-dot-celleditorentervaluemode-x29.md

latest8.9 KB
Original Source

SpreadsheetControl.CloseCellEditor(CellEditorEnterValueMode) Method

Closes the cell editor.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
public bool CloseCellEditor(
    CellEditorEnterValueMode mode
)
vb
Public Function CloseCellEditor(
    mode As CellEditorEnterValueMode
) As Boolean

Parameters

NameTypeDescription
modeCellEditorEnterValueMode

A CellEditorEnterValueMode enumeration member.

|

Returns

TypeDescription
Boolean

true if the cell editor is closed successfully; otherwise, false.

|

Remarks

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.

csharp
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    if (spreadsheetControl1.IsCellEditorActive)
        spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.ActiveCell);
    if (spreadsheetControl1.Modified)
        spreadsheetControl1.SaveDocument();
}
vb
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

csharp
if (spreadsheetControl1.IsCellEditorActive)
    spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.Cancel);
sheet.Rows.Remove(sheet.SelectedCell.TopRowIndex, 1);

winforms-spreadsheet-control-create-a-data-entry-form/CS/DataEntryFormSample/SpreadsheetBindingManager.cs#L269

csharp
if (control != null && control.IsCellEditorActive)
        control.CloseCellEditor(mode);
}

winforms-spreadsheet-bind-to-ms-sql-server-database/CS/SuppliersExample/Form1.cs#L149

csharp
if (spreadsheetControl1.IsCellEditorActive)
        spreadsheetControl1.CloseCellEditor(DevExpress.XtraSpreadsheet.CellEditorEnterValueMode.Default);
}

winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L148

vb
If Equals(sheet.Name, "Invoice") Then
    If spreadsheetControl1.IsCellEditorActive Then spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.Cancel)
    sheet.Rows.Remove(sheet.SelectedCell.TopRowIndex, 1)

winforms-spreadsheet-control-create-a-data-entry-form/VB/DataEntryFormSample/SpreadsheetBindingManager.vb#L240

vb
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

vb
Private Sub CloseInplaceEditor()
    If spreadsheetControl1.IsCellEditorActive Then spreadsheetControl1.CloseCellEditor(DevExpress.XtraSpreadsheet.CellEditorEnterValueMode.Default)
End Sub

See Also

IsCellEditorActive

CellBeginEdit

CellEndEdit

CellCancelEdit

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace