DataGrid.OnMouseDown Method (MouseEventArgs)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Raises the MouseDown event.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

protected override void OnMouseDown(
	MouseEventArgs e
)

Parameters

e
Type: System.Windows.Forms.MouseEventArgs

A MouseEventArgs that contains data about the OnMouseDown event.

Raising an event invokes the event handler through a delegate. For an overview, see NIB: Raising an Event.

Notes to Inheritors:

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

The following code example demonstrates the use of this member.

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);
    }
}

.NET Framework
Available since 1.1
Return to top
Show: