次の方法で共有


DataGrid.OnMouseDown メソッド

MouseDown イベントを発生させます。

Overrides Protected Sub OnMouseDown( _
   ByVal e As MouseEventArgs _)
[C#]
protected override void OnMouseDown(MouseEventArgse);
[C++]
protected: void OnMouseDown(MouseEventArgs* e);
[JScript]
protected override function OnMouseDown(
   e : MouseEventArgs);

パラメータ

解説

イベントが発生すると、デリゲートを使用してイベント ハンドラが呼び出されます。概要については、「 イベントの発生 」を参照してください。

継承時の注意: 派生クラスで OnMouseDown をオーバーライドする場合は、基本クラスの OnMouseDown メソッドを呼び出してください。

使用例

 
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

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

[C++] 
public __gc class MyDataGrid : public 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->X, e->Y);
        if (hit->Row < 0)
            return;
        if (this->IsSelected(hit->Row))
            UnSelect(hit->Row);
        else
            Select(hit->Row);
    }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

DataGrid クラス | DataGrid メンバ | System.Windows.Forms 名前空間