[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Collapse]Get Started With Data Grid and Views
     [Expand]Appearance and Conditional Formatting
     [Expand]Data Editing
     [Collapse]Hit Information
       Tutorial: Hit Information
     [Expand]Data Binding and Working with Columns
     [Expand]Grid View - Columns, Rows and Cells
     [Expand]Banded Views
     [Expand]WinExplorer View
     [Expand]Tile View
     [Expand]Filter and Search
     [Expand]Split Presentation
     [Expand]Row Preview Sections
   [Expand]Data Binding
    Unbound Columns
   [Expand]Data Editing and Validation
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Tutorial: Hit Information

This walkthrough is a transcript of the Hit Information video available on the DevExpress YouTube Channel.

When working with a control like the data grid, you may need to implement custom user interaction, such as display a context menu for data rows or invoke an edit form when double-clicking a row. In these cases, you will need to identify the grid element at the specified coordinates.

In this tutorial, you will learn how to obtain this 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. Whenever end-users right-click a column cell, the column will be filtered against the clicked cell's value. By clicking the auto-filter row, they can clear a filter in an individual column or the entire view.

Expanded Starting Point

Start with an application that has a GridControl with the auto-filter row enabled.

Expanded Obtaining Hit Information on an Element Under the Mouse Cursor

Go to design time, drop the ToolTipController component onto the form and assign it to the grid's EditorContainer.ToolTipController property.

Then, handle the ToolTipController's ToolTipController.GetActiveObjectInfo event. In the event handler, call the View's GridView.CalcHitInfo method, which accepts coordinates within the grid and returns a newly created hit information object containing information on the View's element at the specified location. Use the GridHitInfo.HitTest property to obtain the target element type. Finally, set the element's name as the tooltip text.

Run the application to see the result. When you hover grid control elements with a mouse pointer, the tooltip displays the target element's name.

Expanded Implementing Custom Filtering UI Using Hit Information

Now see how you can use hit information to modify user interaction.

Close the application. Select the grid and handle its MouseDown event. As before, call the GridView.CalcHitInfo method to obtain the hit information object. Check whether it was a right-click and whether the test point is within a grid row.

The GridHitInfo.RowHandle property identifies the clicked row. Check whether this property returns the auto-filter row handle. If the test point is in the auto-filter row's indicator, clear all applied filter conditions by calling the Clear method of the grid's ColumnView.ActiveFilter object. If the click wasn't in the row indicator area, then it must be in one of the columns. Get the target column using the hit info object's GridHitInfo.Column property and clear only this column's filter.

If the click was on a row, but not on the auto-filter row, the code assumes that it was one of the data rows. To obtain the clicked cell's value, call the grid's GridView.GetRowCellValue method and pass the GridHitInfo.RowHandle and GridHitInfo.Column properties of the hit info object. Then, filter the clicked column using the returned value.

Run the application. Right-click any cell with the New status to see that the grid's data is now filtered by this value. In the same manner, filter data by clicking the Low priority and Mike Roller cells. Then, right-click the Priority cell in the auto-filter row to clear this column's filter. Right-click the auto-filter row's indicator to clear all existing filter settings.

Expanded See Also

Is this topic helpful?​​​​​​​