DataGridView.IsCurrentCellDirty Property
Gets a value indicating whether the current cell has uncommitted changes.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System.Booleantrue 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. Sub dataGridView1_CurrentCellDirtyStateChanged( _ ByVal sender As Object, ByVal e As EventArgs) _ Handles dataGridView1.CurrentCellDirtyStateChanged If dataGridView1.IsCurrentCellDirty Then dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit) End If End Sub ' If a check box cell is clicked, this event handler disables ' or enables the button in the same row as the clicked cell. Public Sub dataGridView1_CellValueChanged(ByVal sender As Object, _ ByVal e As DataGridViewCellEventArgs) _ Handles dataGridView1.CellValueChanged If dataGridView1.Columns(e.ColumnIndex).Name = "CheckBoxes" Then Dim buttonCell As DataGridViewDisableButtonCell = _ CType(dataGridView1.Rows(e.RowIndex).Cells("Buttons"), _ DataGridViewDisableButtonCell) Dim checkCell As DataGridViewCheckBoxCell = _ CType(dataGridView1.Rows(e.RowIndex).Cells("CheckBoxes"), _ DataGridViewCheckBoxCell) buttonCell.Enabled = Not CType(checkCell.Value, [Boolean]) dataGridView1.Invalidate() End If End Sub
Available since 2.0