Back to Devexpress

Hit Information

wpf-7557-controls-and-libraries-data-grid-miscellaneous-hit-information.md

latest3.7 KB
Original Source

Hit Information

  • Apr 01, 2021
  • 2 minutes to read

Hit testing allows you to recognize which element is located at the specified screen coordinates. For instance, you may have to determine which part of a View a user has clicked or double-clicked. To obtain this information, use the TableView.CalcHitInfo method (CardView.CalcHitInfo in a card view, TreeListView.CalcHitInfo in a treelist view). This method accepts a test dependency object and returns the hit info object, containing information about the test object’s position within a view.

Each type of View provides its own hit info object (see the table below):

Hit Info ObjectDescription
GridViewHitInfoBaseServes as the base for classes providing information about a specific object within a View.
TableViewHitInfoContains the information about a specific object within a table view.
CardViewHitInfoContains the information about a specific object within a card view.
TreeListViewHitInfoContains the information about a specific object within a treelist view.

Properties provided by hit info objects allow you to obtain:

To get Hit-Test information of a detail grid, call master grid methods.

Example

This example shows how to determine which element in a table view is located under the mouse pointer.

csharp
private void grid_MouseMove(object sender, MouseEventArgs e) {
    TableViewHitInfo hi =
        ((TableView)grid.View).CalcHitInfo(e.OriginalSource as DependencyObject);
    textBlock.Text = hi.HitTest.ToString();
}
vb
Private Sub gridControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim hi As TableViewHitInfo = CType(gridControl1.View, TableView).CalcHitInfo(TryCast(e.OriginalSource, DependencyObject))
    textBlock.Text = hi.HitTest.ToString()
End Sub