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.

適用対象

こちらもご覧ください