Språk

DataGridView.CellMouseDown Händelse

Definition

Inträffar när användaren trycker på en musknapp medan muspekaren ligger inom gränserna för en cell.

public:
 event System::Windows::Forms::DataGridViewCellMouseEventHandler ^ CellMouseDown;
public event System.Windows.Forms.DataGridViewCellMouseEventHandler CellMouseDown;
public event System.Windows.Forms.DataGridViewCellMouseEventHandler? CellMouseDown;
member this.CellMouseDown : System.Windows.Forms.DataGridViewCellMouseEventHandler 
Public Custom Event CellMouseDown As DataGridViewCellMouseEventHandler 

Händelsetyp

Exempel

Följande kodexempel visar hur den här medlemmen används. I exemplet rapporterar en händelsehanterare om händelsens CellMouseDown förekomst. Den här rapporten hjälper dig att lära dig när händelsen inträffar och kan hjälpa dig att felsöka. Om du vill rapportera om flera händelser eller händelser som inträffar ofta kan du överväga att MessageBox.Show ersätta med Console.WriteLine eller lägga till meddelandet i en flerradig TextBox.

Om du vill köra exempelkoden klistrar du in den i ett projekt som innehåller en instans av typen DataGridView med namnet DataGridView1. Kontrollera sedan att händelsehanteraren är associerad med CellMouseDown händelsen.

private void DataGridView1_CellMouseDown(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(), "CellMouseDown Event" );
}
Private Sub DataGridView1_CellMouseDown(sender as Object, e as DataGridViewCellMouseEventArgs) _ 
     Handles DataGridView1.CellMouseDown

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Button", e.Button)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Clicks", e.Clicks)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "X", e.X)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Y", e.Y)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Delta", e.Delta)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Location", e.Location)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"CellMouseDown Event")

End Sub

Kommentarer

Den här händelsen inträffar när användaren trycker på någon av musknapparna. Använd egenskapen MouseEventArgs.Button för att avgöra vilken knapp som klickades.

Mer information om hur du hanterar händelser finns i Hantera och höja händelser.

Gäller för

Se även