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.

CD_ToolTips_SetForGridColumn_New

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:

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;
}