共用方式為


DataGridViewCell.OnMouseClick(DataGridViewCellMouseEventArgs) 方法

定義

當滑鼠指標在儲存格上,使用者按一下滑鼠按鈕時呼叫。

protected:
 virtual void OnMouseClick(System::Windows::Forms::DataGridViewCellMouseEventArgs ^ e);
protected virtual void OnMouseClick (System.Windows.Forms.DataGridViewCellMouseEventArgs e);
abstract member OnMouseClick : System.Windows.Forms.DataGridViewCellMouseEventArgs -> unit
override this.OnMouseClick : System.Windows.Forms.DataGridViewCellMouseEventArgs -> unit
Protected Overridable Sub OnMouseClick (e As DataGridViewCellMouseEventArgs)

參數

範例

下列程式碼範例示範如何使用這個方法。

// Override OnMouseClick in a class derived from DataGridViewCell to 
// enter edit mode when the user clicks the cell. 
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
{
    if (base.DataGridView != null)
    {
        Point point1 = base.DataGridView.CurrentCellAddress;
        if (point1.X == e.ColumnIndex &&
            point1.Y == e.RowIndex &&
            e.Button == MouseButtons.Left &&
            base.DataGridView.EditMode !=
            DataGridViewEditMode.EditProgrammatically)
        {
            base.DataGridView.BeginEdit(true);
        }
    }
}
' Override OnMouseClick in a class derived from DataGridViewCell to 
' enter edit mode when the user clicks the cell. 
Protected Overrides Sub OnMouseClick( _
    ByVal e As DataGridViewCellMouseEventArgs)

    If MyBase.DataGridView IsNot Nothing Then

        Dim point1 As Point = MyBase.DataGridView.CurrentCellAddress
        If point1.X = e.ColumnIndex And _
            point1.Y = e.RowIndex And _
            e.Button = MouseButtons.Left And _
            Not MyBase.DataGridView.EditMode = _
            DataGridViewEditMode.EditProgrammatically Then

            MyBase.DataGridView.BeginEdit(True)

        End If
    End If
End Sub

備註

這個方法類似于 DataGridView.OnCellMouseClick 方法。 它會在引發事件的相同情況下 DataGridView.CellMouseClick 呼叫,但實際上不會引發事件。

適用於

另請參閱