DataGrid.OnMouseDown(MouseEventArgs) Method

Definition

Raises the MouseDown event.

C#
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e);

Parameters

e
MouseEventArgs

A MouseEventArgs that contains data about the OnMouseDown(MouseEventArgs) event.

Examples

The following code example demonstrates the use of this member.

C#
public class MyDataGrid : DataGrid 
{
    // Override the OnMouseDown event to select the whole row
    // when the user clicks anywhere on a row.
    protected override void OnMouseDown(MouseEventArgs e) 
    {
        // Get the HitTestInfo to return the row and pass
        // that value to the IsSelected property of the DataGrid.
        DataGrid.HitTestInfo hit = this.HitTest(e.X, e.Y);
        if (hit.Row < 0)
            return;
        if (this.IsSelected(hit.Row))
            UnSelect(hit.Row);
        else
            Select(hit.Row);
    }
}

Remarks

Raising an event invokes the event handler through a delegate. For an overview, see Handling and Raising Events.

Notes to Inheritors

When overriding OnMouseDown(MouseEventArgs) in a derived class, be sure to call the base class's OnMouseDown(MouseEventArgs) method.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0