特定の Point を使用して、クリックされたグリッド上のポイントの行番号や列番号など、グリッドに関する情報を取得します。
Overloads Public Function HitTest( _
ByVal position As Point _) As HitTestInfo
[C#]
public HitTestInfo HitTest(
Pointposition);
[C++]
public: HitTestInfo* HitTest(
Pointposition);
[JScript]
public function HitTest(
position : Point) : HitTestInfo;
パラメータ
- position
単一の x、y 座標を表す Point 。
戻り値
グリッドに関する固有の情報を格納する DataGrid.HitTestInfo 。
解説
DataGrid.HitTestInfo は、 System.Windows.Forms.DataGrid コントロール内のどの部分をユーザーがクリックしたかを判断するために、 System.Windows.Forms.DataGrid コントロールの HitTest メソッドと組み合わせて使用されます。 DataGrid.HitTestInfo には、行と列の両方と、グリッド内のクリックされた部分に関する情報が格納されます。また、 Type プロパティでは DataGrid.HitTestType 列挙体を返します。
HitTest メソッドでは、 System.Windows.Forms.DataGrid コントロールの DragDrop 、 DragEnter 、 DragOver 、 MouseDown 、 MouseMove 、 MouseUp 、 MouseWheel の各イベントによって提供される引数、 x および y を使用します。
使用例
[Visual Basic] ユーザーがグリッドをクリックすると発生する HitTest メソッドの使用例を次に示します。
Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim hti As DataGrid.HitTestInfo
hti = grid.HitTest(New Point(e.X, e.Y))
Select Case hti.Type
Case System.Windows.Forms.DataGrid.HitTestType.None
Console.WriteLine("You clicked the background.")
Case System.Windows.Forms.DataGrid.HitTestType.Cell
Console.WriteLine("You clicked cell at row " & hti.Row & ", col " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
Console.WriteLine("You clicked the column header for column " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.RowHeader
Console.WriteLine("You clicked the row header for row " & hti.Row)
Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
Console.WriteLine("You clicked the column resizer for column " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.RowResize
Console.WriteLine("You clicked the row resizer for row " & hti.Row)
Case System.Windows.Forms.DataGrid.HitTestType.Caption
Console.WriteLine("You clicked the caption")
Case System.Windows.Forms.DataGrid.HitTestType.ParentRows
Console.WriteLine("You clicked the parent row")
End Select
End Sub
[C#, C++, JScript] C#、C++、および JScript のサンプルはありません。Visual Basic のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
DataGrid クラス | DataGrid メンバ | System.Windows.Forms 名前空間 | DataGrid.HitTest オーバーロードの一覧 | MouseDown