VB / C# – DataGridViewCheckBoxCell déclencher l’événement seulement sur la checkbox et non sur la cellule

VB.NET :

PrivateSub dg_CurrentCellDirtyStateChanged(sender As System.Object, e As System.EventArgs) Handles dg.CurrentCellDirtyStateChanged

IfTypeOf dgEcriture.CurrentCell IsDataGridViewCheckBoxCellThen
dg.CommitEdit(DataGridViewDataErrorContexts.Commit)
EndIf

EndSub

PrivateSub dg_CellValueChanged(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellValueChanged

‘ Traitement à faire
  
EndSub

C# :

 private void dg_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//Traitement à faire
}

private void dg_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dg.CurrentCell is DataGridViewCheckBoxCell)
{
dg.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s