Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DataGrid.HitTestInfo Class

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

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public sealed class HitTestInfo

The DataGrid.HitTestInfo type exposes the following members.

  NameDescription
Public propertyColumnGets the number of the column the user has clicked.
Public propertyRowGets the number of the row the user has clicked.
Public propertyTypeGets the part of the System.Windows.Forms.DataGrid control, other than the row or column, that was clicked.
Top
  NameDescription
Public methodEqualsIndicates whether two objects are identical. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeGets the hash code for the DataGrid.HitTestInfo instance. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringGets the type, row number, and column number. (Overrides Object.ToString().)
Top
  NameDescription
Public fieldStatic memberNowhereIndicates that a coordinate corresponds to part of the System.Windows.Forms.DataGrid control that is not functioning.
Top

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.

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.


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



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.