DataGridView.CancelRowEdit イベント

定義

DataGridView コントロールの VirtualMode プロパティが true で、行の編集をキャンセルした場合に発生します。

public:
 event System::Windows::Forms::QuestionEventHandler ^ CancelRowEdit;
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 示しています。 コントロールが編集モードの場合、 rowInEdit 変数は編集中の行のインデックスを保持し customerInEdit 、変数はその行に対応する Customer オブジェクトへの参照を保持します。 ユーザーが編集モードを取り消すと、このオブジェクトを破棄できます。 ただし、ユーザーが編集していた行が新しいレコードの行である場合、ユーザーが再び編集を開始できるように、古い Customer オブジェクトは破棄され、新しいものに置き換えられます。 この例は、「チュートリアル: Windows フォーム DataGridView コントロールでの仮想モードの実装」で使用できる大きな例の一部です。

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が仮想モードの場合、変更は既定でセル レベルでデータ キャッシュにコミットされます。 イベントは CancelRowEdit 、行レベルのトランザクションを実装するときに使用できます。

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。

適用対象

こちらもご覧ください