DataGridView.CancelRowEdit Événement
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Se produit lorsque la propriété VirtualMode d'un contrôle DataGridView a la valeur true
et annule les modifications sur une ligne.
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
Type d'événement
Exemples
L’exemple de code suivant montre comment gérer cet événement pour un DataGridView contrôle en mode virtuel. Lorsque le contrôle est en mode édition, la rowInEdit
variable contient l’index de la ligne en cours de modification et la customerInEdit
variable contient une référence à un objet Customer correspondant à cette ligne. Lorsque l’utilisateur annule le mode édition, cet objet peut être ignoré. Toutefois, si la ligne que l’utilisateur a modifiée est la ligne pour les nouveaux enregistrements, l’ancien objet Customer est ignoré et remplacé par un nouvel objet afin que l’utilisateur puisse recommencer à apporter des modifications. Cet exemple fait partie d’un exemple plus large disponible dans Procédure pas à pas : implémentation du mode virtuel dans le contrôle 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
Remarques
Lorsque le DataGridView est en mode virtuel, les modifications sont validées dans le cache de données au niveau de la cellule par défaut. L’événement CancelRowEdit peut être utilisé lors de l’implémentation de transactions au niveau des lignes.
Pour plus d’informations sur la façon de gérer les événements, consultez gestion et déclenchement d’événements.
S’applique à
Voir aussi
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour