DataGridView.OnMouseClick(MouseEventArgs) 方法     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
引发 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 -> unitProtected Overrides Sub OnMouseClick (e As 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) 方法,以便已注册的委托对事件进行接收。