DataGridView.CancelRowEdit Událost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vyvolá se, VirtualMode když je true
vlastnost DataGridView ovládacího prvku a zruší úpravy v řádku.
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
Event Type
Příklady
Následující příklad kódu ukazuje, jak zpracovat tuto událost pro DataGridView ovládací prvek ve virtuálním režimu. Když je ovládací prvek v režimu úprav, rowInEdit
proměnná obsahuje index upravovaného řádku a customerInEdit
proměnná obsahuje odkaz na objekt Customer odpovídající danému řádku. Když uživatel zruší režim úprav, může být tento objekt zahozen. Pokud je ale řádek, který uživatel upravoval, řádkem pro nové záznamy, starý objekt Customer se zahodí a nahradí se novým objektem, aby uživatel mohl znovu začít provádět úpravy. Tento příklad je součástí většího příkladu, který je k dispozici v návodu: Implementace virtuálního režimu v ovládacím prvku model 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
Poznámky
Když je ve DataGridView virtuálním režimu, změny se ve výchozím nastavení zapíšou do mezipaměti dat na úrovni buňky. Událost CancelRowEdit lze použít při implementaci transakcí na úrovni řádků.
Další informace o zpracování událostí najdete v tématu Zpracování a vyvolávání událostí.
Platí pro
Viz také
Váš názor
https://aka.ms/ContentUserFeedback.
Připravujeme: V průběhu roku 2024 budeme postupně vyřazovat problémy z GitHub coby mechanismus zpětné vazby pro obsah a nahrazovat ho novým systémem zpětné vazby. Další informace naleznete v tématu:Odeslat a zobrazit názory pro