DataGridView.CancelRowEdit Evento
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Se produce cuando la VirtualMode propiedad de un DataGridView control es true y el usuario cancela las modificaciones en una fila.
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
Tipo de evento
Ejemplos
En el ejemplo de código siguiente se muestra cómo controlar este evento para un DataGridView control en modo virtual. Cuando el control está en modo de edición, la rowInEdit variable contiene el índice de la fila que se está editando y la customerInEdit variable contiene una referencia a un objeto Customer correspondiente a esa fila. Cuando el usuario cancela el modo de edición, este objeto se puede descartar. Sin embargo, si la fila que editaba el usuario es la fila de los nuevos registros, el objeto Customer antiguo se descarta y se reemplaza por uno nuevo para que el usuario pueda empezar a realizar modificaciones de nuevo. Este ejemplo forma parte de un ejemplo más grande disponible en Tutorial: Implementación del modo virtual en el control DataGridView de formularios Windows Forms.
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
DataGridView Cuando está en modo virtual, los cambios se confirman en la caché de datos en el nivel de celda de forma predeterminada. El CancelRowEdit evento se puede usar al implementar transacciones de nivel de fila.
Para obtener más información sobre cómo controlar eventos, consulte Control y generación de eventos.