GrapeCity MultiRow Windows Forms Documentation
OnMouseDown Method (Cell)
Example 


A CellMouseEventArgs that contains the event data.
Raises the GcMultiRow.CellMouseDown event associated with the GcMultiRow control.
Syntax
Protected Overridable Sub OnMouseDown( _
   ByVal e As CellMouseEventArgs _
) 
Dim instance As Cell
Dim e As CellMouseEventArgs
 
instance.OnMouseDown(e)
protected virtual void OnMouseDown( 
   CellMouseEventArgs e
)

Parameters

e
A CellMouseEventArgs that contains the event data.
Remarks

Raising an event invokes the event handler through a delegate.

The OnMouseDown method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors: When overriding OnMouseDown in a derived class, be sure to call the base class's OnMouseDown method so that registered delegates receive the event.

Example
The following code example shows how to use this method to customize a cell's mouse behavior. This code example is part of a larger example provided for the IEditingCell interface.
bool _beginMouseDraging = false;

protected override void OnMouseDown(CellMouseEventArgs e)
{
    // Override OnMouseDown method to customize the action.
    if (e.Button == MouseButtons.Left)
    {
        // Assert the cell is current cell.
        if (this.GcMultiRow.CurrentCell.RowIndex == e.RowIndex &&
            this.GcMultiRow.CurrentCell.CellIndex == e.CellIndex)
        {
            bool beginEditSuccess = this.GcMultiRow.BeginEdit(false);

            if (beginEditSuccess)
            {
                this.EditingCellFormattedValue = this.GetValueFromPoint(e.Location);
                this._beginMouseDraging = true;
            }
        }
    }
    base.OnMouseDown(e);
}

protected override void OnMouseMove(CellMouseEventArgs e)
{
    if (this._beginMouseDraging)
    {
        // Drag mouse to change the EditingCellFormattedValue.
        this.EditingCellFormattedValue = this.GetValueFromPoint(e.Location);
    }
    base.OnMouseMove(e);
}

protected override void OnMouseUp(CellMouseEventArgs e)
{
    // When mouse is up, end dragging.
    this._beginMouseDraging = false;
    base.OnMouseUp(e);
}
Private _beginMouseDraging As Boolean = False

    Protected Overloads Overrides Sub OnMouseDown(ByVal e As CellMouseEventArgs)
        ' Override OnMouseDown method to customize the action.
        If e.Button = MouseButtons.Left Then
            ' Assert the cell is current cell.
            If Me.GcMultiRow.CurrentCell.RowIndex = e.RowIndex AndAlso Me.GcMultiRow.CurrentCell.CellIndex = 
e.CellIndex Then
                Dim beginEditSuccess As Boolean = Me.GcMultiRow.BeginEdit(False)

                If beginEditSuccess Then
                    Me.EditingCellFormattedValue = Me.GetValueFromPoint(e.Location)
                    Me._beginMouseDraging = True
                End If
            End If
        End If
        MyBase.OnMouseDown(e)
    End Sub

    Protected Overloads Overrides Sub OnMouseMove(ByVal e As CellMouseEventArgs)
        If Me._beginMouseDraging Then
            ' Drag mouse to change the EditingCellFormattedValue.
            Me.EditingCellFormattedValue = Me.GetValueFromPoint(e.Location)
        End If
        MyBase.OnMouseMove(e)
    End Sub

    Protected Overloads Overrides Sub OnMouseUp(ByVal e As CellMouseEventArgs)
        ' When mouse is up, end dragging.
        Me._beginMouseDraging = False
        MyBase.OnMouseUp(e)
    End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Cell Class
Cell Members
OnMouseClick Method
OnMouseDoubleClick Method
OnMouseUp Method
OnMouseMove Method
OnMouseWheel Method
OnMouseEnter Method
OnMouseLeave Method
CellMouseDown Event

 

 


Copyright © GrapeCity, inc. All rights reserved.