DataGridView.CancelRowEdit Evento

Definición

Se produce cuando la propiedad VirtualMode de un control DataGridView es true y se cancela la edición de una fila.Occurs when the VirtualMode property of a DataGridView control is true and the cancels edits in a row.

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

Ejemplos

En el ejemplo de código siguiente se muestra cómo controlar este evento para un control DataGridView en el modo virtual.The following code example illustrates how to handle this event for a DataGridView control in virtual mode. Cuando el control está en modo de edición, la variable rowInEdit contiene el índice de la fila que se está editando y la variable customerInEdit contiene una referencia a un objeto Customer correspondiente a esa fila.When the control is in edit mode, the rowInEdit variable holds the index of the row being edited, and the customerInEdit variable holds a reference to a Customer object corresponding to that row. Cuando el usuario cancela el modo de edición, este objeto se puede descartar.When the user cancels out of edit mode, this object can be discarded. Sin embargo, si la fila que estaba editando el usuario es la fila de los nuevos registros, el objeto anterior Customer se descarta y se reemplaza con uno nuevo para que el usuario pueda empezar a realizar modificaciones de nuevo.If the row the user was editing is the row for new records, however, the old Customer object is discarded and replaced with a new one so that the user can begin making edits again. Este ejemplo forma parte de un ejemplo más grande disponible en [Walkthrough: Implementar el modo virtual en el control DataGridView Windows Forms @ no__t-0.This example is part of a larger example available in Walkthrough: Implementing Virtual Mode in the Windows Forms DataGridView Control.

void dataGridView1_CancelRowEdit( Object^ /*sender*/,
    System::Windows::Forms::QuestionEventArgs^ /*e*/ )
{
   if ( this->rowInEdit == this->dataGridView1->Rows->Count - 2 &&
        this->rowInEdit == this->customers->Count )
   {
      
      // If the user has canceled the edit of a newly created row, 
      // replace the corresponding Customer object with a new, empty one.
      this->customerInEdit = gcnew Customer;
   }
   else
   {
      
      // If the user has canceled the edit of an existing row, 
      // release the corresponding Customer object.
      this->customerInEdit = nullptr;
      this->rowInEdit = -1;
   }
}


private void dataGridView1_CancelRowEdit(object sender,
    System.Windows.Forms.QuestionEventArgs e)
{
    if (this.rowInEdit == this.dataGridView1.Rows.Count - 2 &&
        this.rowInEdit == this.customers.Count)
    {
        // If the user has canceled the edit of a newly created row, 
        // replace the corresponding Customer object with a new, empty one.
        this.customerInEdit = new Customer();
    }
    else
    {
        // If the user has canceled the edit of an existing row, 
        // release the corresponding Customer object.
        this.customerInEdit = null;
        this.rowInEdit = -1;
    }
}
Private Sub dataGridView1_CancelRowEdit(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.QuestionEventArgs) _
    Handles dataGridView1.CancelRowEdit

    If Me.rowInEdit = Me.dataGridView1.Rows.Count - 2 AndAlso _
        Me.rowInEdit = Me.customers.Count Then

        ' If the user has canceled the edit of a newly created row, 
        ' replace the corresponding Customer object with a new, empty one.
        Me.customerInEdit = New Customer()

    Else

        ' If the user has canceled the edit of an existing row, 
        ' release the corresponding Customer object.
        Me.customerInEdit = Nothing
        Me.rowInEdit = -1

    End If

End Sub

Comentarios

Cuando el DataGridView está en modo virtual, los cambios se confirman de forma predeterminada en la memoria caché de datos en el nivel de celda.When the DataGridView is in virtual mode, changes are committed to the data cache at the cell level by default. Se puede usar el evento CancelRowEdit al implementar transacciones de nivel de fila.The CancelRowEdit event can be used when implementing row-level transactions.

Para obtener más información acerca de cómo controlar eventos, vea controlar y provocar eventos.For more information about how to handle events, see Handling and Raising Events.

Se aplica a

Consulte también: