Export (0) Print
Expand All
Expand Minimize

DataGridView.CurrentCellDirtyStateChanged Event

Occurs when the state of a cell changes in relation to a change in its contents.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public event EventHandler CurrentCellDirtyStateChanged
/** @event */
public void add_CurrentCellDirtyStateChanged (EventHandler value)

/** @event */
public void remove_CurrentCellDirtyStateChanged (EventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

A cell is marked as modified if its contents have changed but the change has not been saved.

This event typically occurs when a cell has been edited but the change has not been committed to the data cache, or when an edit operation is canceled.

For more information about handling events, see Consuming Events.

The following code example demonstrates how to handle the CurrentCellDirtyStateChanged event. In this example, the event handler calls the CommitEdit method to raise the CellValueChanged event and determine the current value of a DataGridViewCheckBoxCell. 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)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

// 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 =
            (DataGridViewDisableButtonCell)dataGridView1.
            Rows[e.RowIndex].Cells["Buttons"];

        DataGridViewCheckBoxCell checkCell =
            (DataGridViewCheckBoxCell)dataGridView1.
            Rows[e.RowIndex].Cells["CheckBoxes"];
        buttonCell.Enabled = !(Boolean)checkCell.Value;

        dataGridView1.Invalidate();
    }
}

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft