Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

DataGridView.CellMouseClick événement

 

Date de publication : novembre 2016

Se produit lorsque l'utilisateur clique dans une cellule avec la souris.

Espace de noms:   System.Windows.Forms
Assembly:  System.Windows.Forms (dans System.Windows.Forms.dll)

public event DataGridViewCellMouseEventHandler CellMouseClick

This event occurs when the user clicks using any of the mouse buttons. Use the P:System.Windows.Forms.MouseEventArgs.Button property to determine which button was clicked.

To detect clicks on the contents of a cell, such as a button or link within a cell, use the E:System.Windows.Forms.DataGridView.CellContentClick event.

The handler for this event receives the column index and row index of the mouse pointer position.

For clicks in a T:System.Windows.Forms.DataGridViewCheckBoxCell, this event occurs before the check box changes value, so if you do not want to calculate the expected value based on the current value, you will typically handle the E:System.Windows.Forms.DataGridView.CellValueChanged event instead. Because that event occurs only when the user-specified value is committed, which typically occurs when focus leaves the cell, you must also handle the E:System.Windows.Forms.DataGridView.CurrentCellDirtyStateChanged event. In that handler, if the current cell is a check box cell, call the M:System.Windows.Forms.DataGridView.CommitEdit(System.Windows.Forms.DataGridViewDataErrorContexts) method and pass in the F:System.Windows.Forms.DataGridViewDataErrorContexts.Commit value.

For more information about handling events, see NIB: Consuming Events.

The following code example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the E:System.Windows.Forms.DataGridView.CellMouseClick event. This report helps you to learn when the event occurs and can assist you in debugging. To report on multiple events or on events that occur frequently, consider replacing Overload:System.Windows.Forms.MessageBox.Show with Overload:System.Console.WriteLine or appending the message to a multiline T:System.Windows.Forms.TextBox.

To run the example code, paste it into a project that contains an instance of type T:System.Windows.Forms.DataGridView named DataGridView1. Then ensure that the event handler is associated with the E:System.Windows.Forms.DataGridView.CellMouseClick event.

private void DataGridView1_CellMouseClick(Object sender, DataGridViewCellMouseEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Button", e.Button );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Clicks", e.Clicks );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "X", e.X );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Y", e.Y );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Delta", e.Delta );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Location", e.Location );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "CellMouseClick Event" );
}

.NET Framework
Disponible depuis 2.0
Retour au début
Afficher: