Export (0) Print
Expand All

DataGrid.HitTestInfo Class

Contains information about a part of the System.Windows.Forms.DataGrid at a specified coordinate. This class cannot be inherited.

For a list of all members of this type, see DataGrid.HitTestInfo Members.

System.Object
   System.Windows.Forms.DataGrid.HitTestInfo

[Visual Basic]
NotInheritable Public Class DataGrid.HitTestInfo
[C#]
public sealed class DataGrid.HitTestInfo
[C++]
public __gc __sealed class DataGrid.HitTestInfo
[JScript]
public class DataGrid.HitTestInfo

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The DataGrid.HitTestInfo class, in conjunction with the HitTest method of the DataGrid control, is used to determine which part of a DataGrid control the user has clicked. The DataGrid.HitTestInfo class contains the row, column, and part of the grid that was clicked. See the DataGrid.HitTestType enumeration returned by the Type property for a complete list of grid parts.

To return a DataGrid.HitTestInfo, invoke the HitTest method from the MouseDown event of DataGrid control. Pass the x and y properties of the MouseEventArgs to the HitTest method.

Example

[Visual Basic, C#, C++] The following example uses the HitTest method in a MouseDown event to return the DataGrid.HitTestInfo object. The row, column, and part of the grid are then printed.

[Visual Basic] 
Public Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
   Console.WriteLine()
   Dim myHitTest As DataGrid.HitTestInfo
   ' Use the DataGrid control's HitTest method with the x and y properties.
   myHitTest = DataGrid1.HitTest(e.X, e.Y)
   Console.WriteLine("Column " & myHitTest.Column)
   Console.WriteLine("Row " & myHitTest.Row)
   Console.WriteLine("Type " & myHitTest.Type)
   Console.WriteLine("ToString " & myHitTest.ToString)
   Console.WriteLine("Format " & myHitTest.Type.ToString)
End Sub


[C#] 
protected void dataGrid1_MouseDown
(object sender, System.Windows.Forms.MouseEventArgs e)
{
   Console.WriteLine();
   System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
   // Use the DataGrid control's HitTest method with the x and y properties.
   myHitTest = dataGrid1.HitTest(e.X,e.Y);
   Console.WriteLine(myHitTest);
   Console.WriteLine("Column " + myHitTest.Column);
   Console.WriteLine("Row " + myHitTest.Row);
   Console.WriteLine("Type " + myHitTest.Type);
   Console.WriteLine("ToString " + myHitTest.ToString());
   Console.WriteLine("Hit " + myHitTest.Type.ToString());
}


[C++] 
protected:
void dataGrid1_MouseDown(Object* /*sender*/, System::Windows::Forms::MouseEventArgs* e)
{
   Console::WriteLine();
   System::Windows::Forms::DataGrid::HitTestInfo* myHitTest;
   // Use the DataGrid control's HitTest method with the x and y properties.
   myHitTest = dataGrid1->HitTest(e->X,e->Y);
   Console::WriteLine(myHitTest);
   Console::WriteLine(S"Column {0}", __box(myHitTest->Column));
   Console::WriteLine(S"Row {0}", __box(myHitTest->Row));
   Console::WriteLine(S"Type {0}", __box(myHitTest->Type));
   Console::WriteLine(S"ToString {0}", myHitTest);
   Console::WriteLine(S"Hit {0}", __box(myHitTest->Type));
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

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

See Also

DataGrid.HitTestInfo Members | System.Windows.Forms Namespace | CurrentCell | GetCellBounds | HitTest | DataGrid.HitTestType

Show:
© 2014 Microsoft