Freigeben über


DataGrid.OnMouseDown-Methode

Löst das MouseDown-Ereignis aus.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Protected Overrides Sub OnMouseDown ( _
    e As MouseEventArgs _
)
'Usage
Dim e As MouseEventArgs

Me.OnMouseDown(e)
protected override void OnMouseDown (
    MouseEventArgs e
)
protected:
virtual void OnMouseDown (
    MouseEventArgs^ e
) override
protected void OnMouseDown (
    MouseEventArgs e
)
protected override function OnMouseDown (
    e : MouseEventArgs
)

Parameter

Hinweise

Durch das Auslösen eines Ereignisses wird der Ereignishandler über einen Delegaten aufgerufen. Eine Übersicht finden Sie unter Auslösen eines Ereignisses.

Hinweise für Erben Beim Überschreiben des OnMouseDown in einer abgeleiteten Klasse müssen Sie unbedingt die OnMouseDown-Methode der Basisklasse aufrufen.

Beispiel

Public Class MyDataGrid
    Inherits DataGrid

    ' Override the OnMouseDown event to select the whole row
    ' when the user clicks anywhere on a row.

    Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
    ' Get the HitTestInfo to return the row and pass
    ' that value to the IsSelected property of the DataGrid.
        Dim hit As DataGrid.HitTestInfo = Me.HitTest(e.X, e.Y)
        If hit.Row < 0 Then
            Return
        End If
        If IsSelected(hit.Row) Then
            UnSelect(hit.Row)
        Else
            [Select](hit.Row)
        End If
    End Sub
End Class
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);
    }
}
public ref class MyDataGrid: public DataGrid
{
protected:

   // Override the OnMouseDown event to select the whole row
   // when the user clicks anywhere on a row.
   virtual void OnMouseDown( MouseEventArgs^ e ) override
   {
      
      // 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);
   }
};
public class MyDataGrid extends DataGrid
{
    // Override the OnMouseDown event to select the whole row
    // when the user clicks anywhere on a row.
    protected 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.get_X(), e.get_Y());
        if (hit.get_Row() < 0) {
            return;
        }
        if (this.IsSelected(hit.get_Row())) {
            UnSelect(hit.get_Row());
        }
        else {
            Select(hit.get_Row());
        }
    } //OnMouseDown
} //MyDataGrid 

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

DataGrid-Klasse
DataGrid-Member
System.Windows.Forms-Namespace