Skip to main content
A newer version of this page is available.
All docs
V17.2

Hit Information Overview

  • 4 minutes to read

Online Video

In this video, you will learn how to obtain hit information. First, you will display tooltips indicating which element is currently under the mouse cursor. Then, you will use hit information to implement custom filtering UI.

Hit Information Overview

Sometimes you may need to recognize which element is located at the specified screen coordinates in applications. For instance, you may have to determine which part of a View the user has clicked or double-clicked. For this purpose, each View type implements the CalcHitInfo method. It accepts a specific point measured in grid control client coordinates as its pt parameter and returns the newly created hit info object containing information on a View’s corresponding element.

Note that different View types have corresponding types of such hit info objects. So, the GridHitInfo object type holds information about a point hit-tested within a Grid View, a CardHitInfo object is Card View specific and the BandedGridHitInfo type corresponds to a banded View. All these types are derived from the BaseHitInfo class, which is the base one for hit info objects.

The image below shows the hit info objects’ inheritance hierarchy.

HitInfo_object_hierarchy.gif

Any hit info object exposes information about a tested point via a number of its properties that can be grouped into four logical categories:

  • properties identifying a View element that contains a test point (for instance, the Band, Column, RowHandle properties identify the band, column and row whose elements are under the test point);
Type Members
CardHitInfo CardHitInfo.Column, CardHitInfo.RowHandle
GridHitInfo GridHitInfo.Column, GridHitInfo.RowHandle
BandedGridHitInfo BandedGridHitInfo.Band, BandedGridHitInfo.Column, GridHitInfo.RowHandle
  • properties indicating whether or not a test point resides over a particular View element (for instance, the InCard, InColumnPanel property indicates whether the test point is over a card and a column panel);
Type Members
CardHitInfo CardHitInfo.InCard, CardHitInfo.InCardButtons, CardHitInfo.InField
GridHitInfo GridHitInfo.InColumn, GridHitInfo.InColumnPanel, GridHitInfo.InGroupColumn, GridHitInfo.InGroupPanel, GridHitInfo.InRow, GridHitInfo.InRowCell
BandedGridHitInfo BandedGridHitInfo.InBandPanel, GridHitInfo.InColumn, GridHitInfo.InColumnPanel, GridHitInfo.InGroupColumn, GridHitInfo.InGroupPanel, GridHitInfo.InRow, GridHitInfo.InRowCell
  • the BaseHitInfo.HitPoint property representing a test point in coordinates relative to a grid’s top-left corner;

 

  • the HitTest property identifying the type of element located under a test point.
Type Member
CardHitInfo CardHitInfo.HitTest (returns one of the CardHitTest enumerator members)
GridHitInfo GridHitInfo.HitTest (returns one of the GridHitTest enumerator members)
BandedGridHitInfo BandedGridHitInfo.HitTest (returns one of the BandedGridHitTest enumerator members)

In some cases you may need to find out which View is located at specified screen coordinates. For this purpose you can use the GridControl.GetViewAt method.

Example

The following sample code shows how to identify the element located at a specific point, using the GridView.CalcHitInfo method.

In the example, the CalcHitInfo method is called when moving over a Grid Control with the mouse. The name of the current View element is displayed in the form’s caption.

using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Base.ViewInfo;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
// ...
private void gridControl1_MouseMove(object sender, MouseEventArgs e) {
    GridControl grid = sender as GridControl;
    if (grid == null) return;
    // Get a View at the current point.
    BaseView view = grid.GetViewAt(e.Location);
    // Retrieve information on the current View element.
    BaseHitInfo baseHI = view.CalcHitInfo(e.Location);
    GridHitInfo gridHI = baseHI as GridHitInfo;
    if (gridHI != null)
        Text = gridHI.HitTest.ToString();
}
See Also