DataGridView.CommitEdit Method

Note: This method is new in the .NET Framework version 2.0.

Commits changes in the current cell to the data cache without ending edit mode.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public bool CommitEdit (
	DataGridViewDataErrorContexts context
public boolean CommitEdit (
	DataGridViewDataErrorContexts context
public function CommitEdit (
	context : DataGridViewDataErrorContexts
) : boolean



A bitwise combination of DataGridViewDataErrorContexts values that specifies the context in which an error can occur.

Return Value

true if the changes were committed; otherwise false.

Exception typeCondition


The cell value could not be committed and either there is no handler for the DataError event or the handler has set the DataGridViewDataErrorEventArgs.ThrowException property to true.

This method attempts to convert the formatted, user-specified value to the underlying cell data type. To do this, it raises the CellParsing event, which you can handle to customize the type conversion. Otherwise, default type converters are used. Conversion errors may result in an exception if the DataError event is not handled to prevent it. If the value is successfully converted, it is committed to the data store, raising the CellValuePushed event for non-data-bound cells when the VirtualMode property value is true. If the value is successfully committed, the CellValueChanged event occurs.

The following code example calls the CommitEdit method within a CurrentCellDirtyStateChanged event handler to raise the CellValueChanged event. This code example is part of a larger example provided in How to: Disable Buttons in a Button Column in the Windows Forms DataGridView Control.

// This event handler manually raises the CellValueChanged event
// by calling the CommitEdit method.
void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
    if (dataGridView1.IsCurrentCellDirty)

// If a check box cell is clicked, this event handler disables  
// or enables the button in the same row as the clicked cell.
public void dataGridView1_CellValueChanged(object sender,
    DataGridViewCellEventArgs e)
    if (dataGridView1.Columns[e.ColumnIndex].Name == "CheckBoxes")
        DataGridViewDisableButtonCell buttonCell =

        DataGridViewCheckBoxCell checkCell =
        buttonCell.Enabled = !(Boolean)checkCell.Value;


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0