DataGridView.UserDeletingRow Evento

Definición

Se produce cuando el usuario elimina una fila del control DataGridView.

C#
public event System.Windows.Forms.DataGridViewRowCancelEventHandler UserDeletingRow;
C#
public event System.Windows.Forms.DataGridViewRowCancelEventHandler? UserDeletingRow;

Tipo de evento

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el UserDeletingRow evento para cancelar la eliminación de filas de DataGridView si la fila de saldo inicial se incluye en la selección. Este ejemplo forma parte de un ejemplo más grande disponible en el SelectionChanged evento .

C#
private void DataGridView1_UserDeletingRow(object sender,
    DataGridViewRowCancelEventArgs e)
{
    DataGridViewRow startingBalanceRow = DataGridView1.Rows[0];

    // Check if the Starting Balance row is included in the selected rows
    if (DataGridView1.SelectedRows.Contains(startingBalanceRow))
    {
        // Do not allow the user to delete the Starting Balance row.
        MessageBox.Show("Cannot delete Starting Balance row!");

        // Cancel the deletion if the Starting Balance row is included.
        e.Cancel = true;
    }
}

Comentarios

Este evento se puede cancelar para evitar que se complete una eliminación de fila.

Para obtener más información acerca de cómo controlar eventos, vea controlar y provocar eventos.

Se aplica a

Producto Versiones
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Consulte también