DataGridView.CancelRowEdit Händelse
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Inträffar när egenskapen för VirtualMode en DataGridView kontroll är true och användaren avbryter redigeringar på en rad.
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
Händelsetyp
Exempel
I följande kodexempel visas hur du hanterar den här händelsen för en DataGridView kontroll i virtuellt läge. När kontrollen är i redigeringsläge innehåller variabeln rowInEdit indexet för raden som redigeras, och variabeln customerInEdit innehåller en referens till ett kundobjekt som motsvarar den raden. När användaren avbryter redigeringsläget kan det här objektet ignoreras. Om raden som användaren redigerade är raden för nya poster ignoreras dock det gamla kundobjektet och ersätts med ett nytt så att användaren kan börja redigera igen. Det här exemplet är en del av ett större exempel i Walkthrough: Implementera virtuellt läge i 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
Kommentarer
DataGridView När är i virtuellt läge checkas ändringar in i datacachen på cellnivå som standard. Händelsen CancelRowEdit kan användas vid implementering av transaktioner på radnivå.
Mer information om hur du hanterar händelser finns i Hantera och höja händelser.