Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

DataGridView.IsCurrentCellDirty Property

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

Gets a value indicating whether the current cell has uncommitted changes.

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

public bool IsCurrentCellDirty { get; }
/** @property */
public boolean get_IsCurrentCellDirty ()

public function get IsCurrentCellDirty () : boolean

Property Value

true if the current cell has uncommitted changes; otherwise, false.

When the DataGridView is not bound to data, the cell edit is considered committed when the user moves to another cell.

If row headers are visible, a pencil glyph is present in the header for the row that contains a cell with uncommitted changes.

If IsCurrentCellDirty is true and the current cell hosts an editing control, you can retrieve it through the EditingControl property.

The following code example uses the IsCurrentCellDirty property to determine whether to commit a cell value and raise the CellValueChanged event from a handler for the CurrentCellDirtyStateChanged 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)
    {
        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 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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.