How to: Display a Tooltip for a Particular Visual Element
- 3 minutes to read
DevExpress controls can consist of multiple visual elements. For example, the grid control consists of column headers, band headers, etc. Certain visual elements already have predefined tooltips. For example, if the text in a grid control’s column header is trimmed, the tooltip displays the entire text. You can also provide custom tooltips for visual elements. For example, you can use the GridColumn.ToolTip or GridBand.ToolTip property to provide a custom tooltip for a column or band header.
If a visual element does not have a dedicated property, you can handle the ToolTipController.GetActiveObjectInfo event to provide a tooltip. Event arguments allow you to determine the visual element under the mouse pointer and specify the tooltip.
Example: Display a Tooltip for a Row Indicator in the Grid Control
This example shows how to display a row number in a tooltip when the mouse pointer hovers a row indicator.
To display the tooltips, do the following:
- drop the ToolTipController component onto the form
- assign the controller to the grid control’s ToolTipController property
- handle the ToolTipController.GetActiveObjectInfo event to specify the tooltip content
- in your event handler, set the event’s Info parameter to a ToolTipControlInfo object that contains tooltip information.
- ensure that the ToolTipControlInfo.Object object uniquely identifies the currently processed visual element.
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
private void toolTipController1_GetActiveObjectInfo(object sender,
ToolTipControllerGetActiveObjectInfoEventArgs e) {
if(e.SelectedControl != gridControl1) return;
ToolTipControlInfo info = null;
// Get the view at the current mouse position.
GridView view = gridControl1.GetViewAt(e.ControlMousePosition) as GridView;
if(view == null) return;
// Get the information about the visual element at the current mouse position.
GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
// Display a hint for a row indicator.
if(hi.HitTest == GridHitTest.RowIndicator) {
// Create an object that uniquely identifies a row indicator.
object o = hi.HitTest.ToString() + hi.RowHandle.ToString();
string text = "Row "+ hi.RowHandle.ToString();
info = new ToolTipControlInfo(o, text);
}
// Assign the tooltip information if applicable; otherwise, preserve the default tooltip.
if (info != null)
e.Info = info;
}