DataGrid.HitTestType Enumeration
Specifies the part of the System.Windows.Forms.DataGrid control the user has clicked.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
[Visual Basic] <Flags> <Serializable> Public Enum DataGrid.HitTestType [C#] [Flags] [Serializable] public enum DataGrid.HitTestType [C++] [Flags] [Serializable] __value public enum DataGrid.HitTestType [JScript] public Flags Serializable enum DataGrid.HitTestType
Remarks
Use the members of this enumeration to determine which part of the grid has been clicked. The Type property of a DataGrid.HitTestInfo returns a DataGrid.HitTestType. The DataGrid.HitTestInfo is created by invoking the HitTest method of a System.Windows.Forms.DataGrid control.
Members
| Member name | Description | Value |
|---|---|---|
| Caption | The caption of the System.Windows.Forms.DataGrid control. | 32 |
| Cell Supported by the .NET Compact Framework. | A cell in the System.Windows.Forms.DataGrid control. | 1 |
| ColumnHeader Supported by the .NET Compact Framework. | A column header in the System.Windows.Forms.DataGrid control. | 2 |
| ColumnResize Supported by the .NET Compact Framework. | The column border, which is the line between column headers. It can be dragged to resize a column's width. | 8 |
| None Supported by the .NET Compact Framework. | The background area, visible when the control contains no table, few rows, or when a table is scrolled to its bottom. | 0 |
| ParentRows | The parent row section of the System.Windows.Forms.DataGrid control. The parent row displays information from or about the parent table of the currently displayed child table, such as the name of the parent table, column names and values of the parent record. | 64 |
| RowHeader Supported by the .NET Compact Framework. | A row header in the System.Windows.Forms.DataGrid control. | 4 |
| RowResize Supported by the .NET Compact Framework. | The row border, which is the line between grid row headers. It can be dragged to resize a row's height. | 16 |
Example
[Visual Basic, C#, C++] The following example uses the HitTest method in a MouseDown event to return the DataGrid.HitTestInfo. The row, column, and part of the grid are then printed.
[Visual Basic] Protected Sub dataGrid1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Dim newLine As String = ControlChars.Cr Console.WriteLine(newLine) Dim myHitTest As System.Windows.Forms.DataGrid.HitTestInfo ' 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 " & ReturnHitTest(myHitTest.Type))) End Sub 'dataGrid1_MouseDown Private Function ReturnHitTest(hit As System.Windows.Forms.DataGrid.HitTestType) As String ' Use this function to return the part of the grid clicked. Select Case hit Case System.Windows.Forms.DataGrid.HitTestType.Cell Return "Cell" Case System.Windows.Forms.DataGrid.HitTestType.Caption Return "Caption" Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader Return "ColumnHeader" Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize Return "Resize" Case System.Windows.Forms.DataGrid.HitTestType.ParentRows Return "ParentRows" Case System.Windows.Forms.DataGrid.HitTestType.RowHeader Return "RowHeader" Case System.Windows.Forms.DataGrid.HitTestType.RowResize Return "RowResize" Case System.Windows.Forms.DataGrid.HitTestType.None Return "None" Case Else Return "Unknown" End Select End Function 'ReturnHitTest [C#] protected void dataGrid1_MouseDown (object sender, System.Windows.Forms.MouseEventArgs e) { string newLine = "\n"; Console.WriteLine(newLine); 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 " + ReturnHitTest(myHitTest.Type )); } private string ReturnHitTest(System.Windows.Forms.DataGrid.HitTestType hit ){ // Use this function to return the part of the grid clicked. switch(hit) { case(System.Windows.Forms.DataGrid.HitTestType.Cell): return "Cell"; case(System.Windows.Forms.DataGrid.HitTestType.Caption): return "Caption"; case(System.Windows.Forms.DataGrid.HitTestType.ColumnHeader): return "ColumnHeader"; case(System.Windows.Forms.DataGrid.HitTestType.ColumnResize): return "Resize"; case(System.Windows.Forms.DataGrid.HitTestType.ParentRows): return "ParentRows"; case(System.Windows.Forms.DataGrid.HitTestType.RowHeader): return "RowHeader"; case(System.Windows.Forms.DataGrid.HitTestType.RowResize): return "RowResize"; case(System.Windows.Forms.DataGrid.HitTestType.None): return "None"; default:return "Unknown"; } } [C++] protected: void dataGrid1_MouseDown (Object* /*sender*/, System::Windows::Forms::MouseEventArgs* e) { String* newLine = S"\n"; Console::WriteLine(newLine); 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}", ReturnHitTest(myHitTest->Type)); } private: String* ReturnHitTest(System::Windows::Forms::DataGrid::HitTestType hit ){ // Use this function to return the part of the grid clicked. switch(hit) { case(System::Windows::Forms::DataGrid::HitTestType::Cell): return S"Cell"; case(System::Windows::Forms::DataGrid::HitTestType::Caption): return S"Caption"; case(System::Windows::Forms::DataGrid::HitTestType::ColumnHeader): return S"ColumnHeader"; case(System::Windows::Forms::DataGrid::HitTestType::ColumnResize): return S"Resize"; case(System::Windows::Forms::DataGrid::HitTestType::ParentRows): return S"ParentRows"; case(System::Windows::Forms::DataGrid::HitTestType::RowHeader): return S"RowHeader"; case(System::Windows::Forms::DataGrid::HitTestType::RowResize): return S"RowResize"; case(System::Windows::Forms::DataGrid::HitTestType::None): return S"None"; default:return S"Unknown"; } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
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
System.Windows.Forms Namespace | DataGrid.HitTestInfo | HitTest