DataGridView.UserDeletingRow Evento

Definição

Ocorre quando o usuário exclui uma linha do controle DataGridView.

public:
 event System::Windows::Forms::DataGridViewRowCancelEventHandler ^ UserDeletingRow;
public event System.Windows.Forms.DataGridViewRowCancelEventHandler UserDeletingRow;
public event System.Windows.Forms.DataGridViewRowCancelEventHandler? UserDeletingRow;
member this.UserDeletingRow : System.Windows.Forms.DataGridViewRowCancelEventHandler 
Public Custom Event UserDeletingRow As DataGridViewRowCancelEventHandler 

Tipo de evento

Exemplos

O exemplo de código a seguir demonstra como usar o UserDeletingRow evento para cancelar a exclusão de linhas do se a linha de DataGridView saldo inicial estiver incluída na seleção. Este exemplo faz parte de um exemplo maior disponível no SelectionChanged evento.

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;
    }
}
Private Sub UserDeletingRow(ByVal sender As Object, _
    ByVal e As DataGridViewRowCancelEventArgs) _
    Handles DataGridView1.UserDeletingRow

    Dim startingBalanceRow As DataGridViewRow = DataGridView1.Rows(0)

    ' Check if the starting balance row is included in the selected rows
    If DataGridView1.SelectedRows.Contains(startingBalanceRow) Then
        ' 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
    End If
End Sub

Comentários

Esse evento pode ser cancelado para impedir que uma exclusão de linha seja concluída.

Para obter mais informações sobre como lidar com eventos, consulte Manipulando e gerando eventos.

Aplica-se a

Confira também