DataGridView.CancelRowEdit Zdarzenie

Definicja

Występuje, gdy VirtualMode właściwość kontrolki DataGridView jest true i anuluje edycje w wierszu.

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 

Typ zdarzenia

Przykłady

Poniższy przykład kodu ilustruje sposób obsługi tego zdarzenia dla kontrolki DataGridView w trybie wirtualnym. Gdy kontrolka jest w trybie edycji, rowInEdit zmienna przechowuje indeks edytowanego wiersza, a zmienna customerInEdit zawiera odwołanie do obiektu Customer odpowiadającego temu wierszowi. Gdy użytkownik anuluje tryb edycji, ten obiekt można odrzucić. Jeśli wiersz edytowany przez użytkownika jest wierszem dla nowych rekordów, jednak stary obiekt Customer zostanie odrzucony i zastąpiony nowym, aby użytkownik mógł rozpocząć ponowne wprowadzanie zmian. Ten przykład jest częścią większego przykładu dostępnego w przewodniku: implementowanie trybu wirtualnego w kontrolce DataGridView Windows Forms.

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

Uwagi

Gdy element DataGridView jest w trybie wirtualnym, zmiany są domyślnie zatwierdzane w pamięci podręcznej danych na poziomie komórki. Zdarzenie CancelRowEdit może być używane podczas implementowania transakcji na poziomie wiersza.

Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i podnoszenie zdarzeń.

Dotyczy

Zobacz też