Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [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
   [Expand]Getting Started
   [Expand]Binding to Data
   [Expand]Grid View
   [Expand]View Technology
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Summaries
   [Expand]Data Editing
   [Expand]Filtering and Locating Rows
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Collapse]Hit Information
     Hit Information Overview
     Tutorial: Hit Information
     Samples of Using Hit Information
   [Expand]Hints
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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

How would you rate this topic?​​​​​​​