DataGridView.RowDirtyStateNeeded DataGridView.RowDirtyStateNeeded DataGridView.RowDirtyStateNeeded DataGridView.RowDirtyStateNeeded Event

Definition

Occurs when the VirtualMode property of the DataGridView control is true and the DataGridView needs to determine whether the current row has uncommitted changes.

public:
 event System::Windows::Forms::QuestionEventHandler ^ RowDirtyStateNeeded;
public event System.Windows.Forms.QuestionEventHandler RowDirtyStateNeeded;
member this.RowDirtyStateNeeded : System.Windows.Forms.QuestionEventHandler 
Public Custom Event RowDirtyStateNeeded As QuestionEventHandler 

Examples

The following code example demonstrates how to handle this event to provide cell-level commit scope, meaning that the user can revert changes to the current cell only. In cell-level commit scope, the row is treated as having uncommitted changes only when the current cell has uncommitted changes, rather than when any cell in the row has uncommitted changes. This example is part of a larger example available in Walkthrough: Implementing Virtual Mode in the Windows Forms DataGridView Control.

void dataGridView1_RowDirtyStateNeeded( Object^ /*sender*/,
    System::Windows::Forms::QuestionEventArgs^ e )
{
   if (  !rowScopeCommit )
   {
      
      // In cell-level commit scope, indicate whether the value
      // of the current cell has been modified.
      e->Response = this->dataGridView1->IsCurrentCellDirty;
   }
}


private void dataGridView1_RowDirtyStateNeeded(object sender,
    System.Windows.Forms.QuestionEventArgs e)
{
    if (!rowScopeCommit)
    {
        // In cell-level commit scope, indicate whether the value
        // of the current cell has been modified.
        e.Response = this.dataGridView1.IsCurrentCellDirty;
    }
}
Private Sub dataGridView1_RowDirtyStateNeeded(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.QuestionEventArgs) _
    Handles dataGridView1.RowDirtyStateNeeded

    If Not rowScopeCommit Then

        ' In cell-level commit scope, indicate whether the value
        ' of the current cell has been modified.
        e.Response = Me.dataGridView1.IsCurrentCellDirty

    End If

End Sub

Remarks

By default, this event sets the QuestionEventArgs.Response property to true if any cells in the current row have been modified. This causes the CancelRowEdit event to occur when the user reverts edits to a row. Users can revert edits to a row by pressing ESC twice when a cell is in edit mode or once outside of edit mode. This event can be used for customizing commit scope in virtual mode by setting the QuestionEventArgs.Response property to the correct value depending on the chosen commit scope.

For more information about how to handle events, see Handling and Raising Events.

Applies to

See also