DataGridView.UserDeletingRow DataGridView.UserDeletingRow DataGridView.UserDeletingRow DataGridView.UserDeletingRow Event

정의

사용자가 DataGridView 컨트롤에서 행을 삭제하면 발생합니다.Occurs when the user deletes a row from the DataGridView control.

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 

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 UserDeletingRow 에서 행의 삭제를 취소 하려면 이벤트를 DataGridView 균형을 시작할 행 선택 영역에 포함 되어 있으면 합니다.The following code example demonstrates how to use the UserDeletingRow event to cancel the deletion of rows from the DataGridView if the starting balance row is included in the selection. 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부는 SelectionChanged 이벤트입니다.This example is part of a larger example available in the SelectionChanged event.

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

설명

완료 되는 행 삭제를 방지 하기 위해이 이벤트를 취소할 수 있습니다.This event can be canceled to prevent a row deletion from being completed.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about how to handle events, see Handling and Raising Events.

적용 대상

추가 정보