DataGridView.OnMouseClick(MouseEventArgs) 方法

定義

引發 MouseClick 事件。

protected:
 override void OnMouseClick(System::Windows::Forms::MouseEventArgs ^ e);
protected override void OnMouseClick (System.Windows.Forms.MouseEventArgs e);
override this.OnMouseClick : System.Windows.Forms.MouseEventArgs -> unit
Protected Overrides Sub OnMouseClick (e As MouseEventArgs)

參數

e
MouseEventArgs

MouseEventArgs,其中包含事件資料。

例外狀況

這個控制項設定成在收到焦點時進入編輯模式,但編輯儲存格值的初始設定失敗,DataError 事件沒有處理常式,或處理常式已將 ThrowException 屬性設定為 true。 例外狀況物件通常可轉換成 FormatException 類型。

範例

下列程式碼範例示範此方法的使用方式。

// 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

備註

引發事件會透過委派叫用此事件處理常式。 如需詳細資訊,請參閱 處理和引發事件

OnMouseClick 方法也允許衍生類別處理事件,而不用附加委派。 這是在衍生類別中處理事件的慣用技巧。

給繼承者的注意事項

當在衍生類別中覆寫 OnMouseClick(MouseEventArgs) 時,請確定呼叫基底類別的 OnMouseClick(MouseEventArgs) 方法,使已註冊的委派能接收到事件。

適用於

另請參閱