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 Forms 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 수준 트랜잭션을 구현할 때 이벤트를 사용할 수 있습니다.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상

추가 정보