DataGridView.CancelRowEdit DataGridView.CancelRowEdit DataGridView.CancelRowEdit DataGridView.CancelRowEdit Event

定義

DataGridView コントロールの VirtualMode プロパティが true で、行の編集をキャンセルした場合に発生します。Occurs when the VirtualMode property of a DataGridView control is true and the cancels edits in a row.

public:
 event System::Windows::Forms::QuestionEventHandler ^ CancelRowEdit;
public event System.Windows.Forms.QuestionEventHandler CancelRowEdit;
member this.CancelRowEdit : System.Windows.Forms.QuestionEventHandler 
Public Custom Event CancelRowEdit As QuestionEventHandler 

次のコード例は、このイベントを処理する方法を示しています、DataGridView仮想モードで制御します。The following code example illustrates how to handle this event for a DataGridView control in virtual mode. コントロールが編集モードの場合、rowInEdit変数が編集される行のインデックスを保持し、customerInEdit変数はその行に対応する顧客オブジェクトへの参照を保持します。When the control is in edit mode, the rowInEdit variable holds the index of the row being edited, and the customerInEdit variable holds a reference to a Customer object corresponding to that row. ユーザーが編集モードを解除を取り消したときにこのオブジェクトを破棄できます。When the user cancels out of edit mode, this object can be discarded. ユーザーが編集した行が新しいレコードの行の場合は、ただし、古い Customer オブジェクトが破棄され、もう一度編集を行ってユーザーが開始できるように、新しいに置き換えられます。If the row the user was editing is the row for new records, however, the old Customer object is discarded and replaced with a new one so that the user can begin making edits again. この例で使用できる例の一部は、チュートリアル。仮想モードの実装で、Windows フォーム DataGridView コントロールします。This example is part of a larger example available in Walkthrough: Implementing Virtual Mode in the Windows Forms DataGridView Control.

void dataGridView1_CancelRowEdit( Object^ /*sender*/,
    System::Windows::Forms::QuestionEventArgs^ /*e*/ )
{
   if ( this->rowInEdit == this->dataGridView1->Rows->Count - 2 &&
        this->rowInEdit == this->customers->Count )
   {
      
      // If the user has canceled the edit of a newly created row, 
      // replace the corresponding Customer object with a new, empty one.
      this->customerInEdit = gcnew Customer;
   }
   else
   {
      
      // If the user has canceled the edit of an existing row, 
      // release the corresponding Customer object.
      this->customerInEdit = nullptr;
      this->rowInEdit = -1;
   }
}


private void dataGridView1_CancelRowEdit(object sender,
    System.Windows.Forms.QuestionEventArgs e)
{
    if (this.rowInEdit == this.dataGridView1.Rows.Count - 2 &&
        this.rowInEdit == this.customers.Count)
    {
        // If the user has canceled the edit of a newly created row, 
        // replace the corresponding Customer object with a new, empty one.
        this.customerInEdit = new Customer();
    }
    else
    {
        // If the user has canceled the edit of an existing row, 
        // release the corresponding Customer object.
        this.customerInEdit = null;
        this.rowInEdit = -1;
    }
}
Private Sub dataGridView1_CancelRowEdit(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.QuestionEventArgs) _
    Handles dataGridView1.CancelRowEdit

    If Me.rowInEdit = Me.dataGridView1.Rows.Count - 2 AndAlso _
        Me.rowInEdit = Me.customers.Count Then

        ' If the user has canceled the edit of a newly created row, 
        ' replace the corresponding Customer object with a new, empty one.
        Me.customerInEdit = New Customer()

    Else

        ' If the user has canceled the edit of an existing row, 
        ' release the corresponding Customer object.
        Me.customerInEdit = Nothing
        Me.rowInEdit = -1

    End If

End Sub

注釈

ときに、DataGridViewが仮想モードでは変更は既定では、セル レベルでデータ キャッシュにコミットします。When the DataGridView is in virtual mode, changes are committed to the data cache at the cell level by default. CancelRowEdit行レベルのトランザクションを実装するときにイベントを使用できます。The CancelRowEdit event can be used when implementing row-level transactions.

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。For more information about how to handle events, see Handling and Raising Events.

適用対象

こちらもご覧ください