DataGridView.UserDeletingRow Olay

Tanım

Kullanıcı denetimden DataGridView bir satır sildiğinde gerçekleşir.

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 

Olay Türü

Örnekler

Aşağıdaki kod örneği, başlangıç bakiyesi satırı seçime dahil edildiyse içindeki satırların DataGridView silinmesini iptal etmek için olayının nasıl kullanılacağını UserDeletingRow gösterir. Bu örnek, olayda SelectionChanged kullanılabilen daha büyük bir örneğin parçasıdır.

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

Açıklamalar

Bu olay, satır silme işleminin tamamlanmasını önlemek için iptal edilebilir.

Olayları işleme hakkında daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.

Şunlara uygulanır

Ayrıca bkz.