Export (0) Print
Expand All
Expand Minimize

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.

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

[FlagsAttribute]
public enum HitTestType

Member nameDescription
CaptionThe caption of the System.Windows.Forms.DataGrid control.
CellA cell in the System.Windows.Forms.DataGrid control.
ColumnHeaderA column header in the System.Windows.Forms.DataGrid control.
ColumnResizeThe column border, which is the line between column headers. It can be dragged to resize a column's width.
NoneThe background area, visible when the control contains no table, few rows, or when a table is scrolled to its bottom.
ParentRowsThe 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.
RowHeaderA row header in the System.Windows.Forms.DataGrid control.
RowResizeThe row border, which is the line between grid row headers. It can be dragged to resize a row's height.

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.

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.

private 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";
    }
 }

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft