Ticket Q568447
Visible to All Users

Show tooltip with property value for ListView grid cells

created 11 years ago

Customer (table) has and OID that points to Address (table) the default list view shows the Address.Name, that fine. But in the table Address we also have a calculated field that is made up of Name, Address1, etc…
Is there anyway to show this as a multiline tooltip when they hover over this item in the List View, we do add the CR and LF in the Computed value.

Answers approved by DevExpress Support

created 11 years ago (modified 7 years ago)

Hello Joe,
In WinForms it is possible to accomplish this task via the ToolTipController component. Here is an example:

C#
using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Win.Editors; using DevExpress.Utils; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; using MainDemo.Module.BusinessObjects; namespace MainDemo.Module.Win { public class WinViewController1 : ObjectViewController<ListView, Contact> { ToolTipController tooltipController; protected override void OnActivated() { base.OnActivated(); tooltipController = new ToolTipController(); tooltipController.GetActiveObjectInfo += tooltipController_GetActiveObjectInfo; } protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); GridListEditor gridListEditor = View.Editor as GridListEditor; if(gridListEditor != null) { gridListEditor.Grid.ToolTipController = tooltipController; } } void tooltipController_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e) { if(e.SelectedControl is GridControl) { GridView view = ((GridControl)e.SelectedControl).GetViewAt(e.ControlMousePosition) as GridView; if(view == null) return; GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition); if(hi.HitTest == GridHitTest.RowCell && hi.Column != null && hi.Column.FieldName == "Manager!") { Contact relatedContact = (Contact)view.GetRowCellValue(hi.RowHandle, hi.Column); if(relatedContact != null) { object toolTipInfoIdentifier = String.Format("{0}_{1}_{2}", hi.HitTest.ToString(), hi.RowHandle.ToString(), hi.Column.FieldName); e.Info = new ToolTipControlInfo(toolTipInfoIdentifier, relatedContact.FullName); } } } } protected override void OnDeactivated() { base.OnDeactivated(); if(tooltipController != null) { tooltipController.GetActiveObjectInfo -= tooltipController_GetActiveObjectInfo; tooltipController = null; } } } }
Visual Basic
Imports System Imports DevExpress.ExpressApp Imports DevExpress.ExpressApp.Win.Editors Imports DevExpress.Utils Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraGrid.Views.Grid.ViewInfo Imports MainDemo.Module.BusinessObjects Namespace MainDemo.Module.Win Public Class WinViewController1 Inherits ObjectViewController(Of ListView, Contact) Private tooltipController As ToolTipController Protected Overrides Sub OnActivated() MyBase.OnActivated() tooltipController = New ToolTipController() AddHandler tooltipController.GetActiveObjectInfo, AddressOf tooltipController_GetActiveObjectInfo End Sub Protected Overrides Sub OnViewControlsCreated() MyBase.OnViewControlsCreated() Dim gridListEditor As GridListEditor = TryCast(View.Editor, GridListEditor) If gridListEditor IsNot Nothing Then gridListEditor.Grid.ToolTipController = tooltipController End If End Sub Private Sub tooltipController_GetActiveObjectInfo(ByVal sender As Object, ByVal e As ToolTipControllerGetActiveObjectInfoEventArgs) If TypeOf e.SelectedControl Is GridControl Then Dim view As GridView = TryCast(CType(e.SelectedControl, GridControl).GetViewAt(e.ControlMousePosition), GridView) If view Is Nothing Then Return End If Dim hi As GridHitInfo = view.CalcHitInfo(e.ControlMousePosition) If hi.HitTest = GridHitTest.RowCell AndAlso hi.Column IsNot Nothing AndAlso hi.Column.FieldName = "Manager!" Then Dim relatedContact As Contact = CType(view.GetRowCellValue(hi.RowHandle, hi.Column), Contact) If relatedContact IsNot Nothing Then Dim toolTipInfoIdentifier As Object = String.Format("{0}_{1}_{2}", hi.HitTest.ToString(), hi.RowHandle.ToString(), hi.Column.FieldName) e.Info = New ToolTipControlInfo(toolTipInfoIdentifier, relatedContact.FullName) End If End If End If End Sub Protected Overrides Sub OnDeactivated() MyBase.OnDeactivated() If tooltipController IsNot Nothing Then RemoveHandler tooltipController.GetActiveObjectInfo, AddressOf tooltipController_GetActiveObjectInfo tooltipController = Nothing End If End Sub End Class End Namespace

Note that it is possible to display the calculated property in the lookup column as well. Refer to the How to: Specify a Display Member for a Lookup Editor topic to learn how to do this.

In ASP.NET WebForms you can use a solution from the ASPxGridListEditor: ToolTip in Data thread.

    Comments (3)

      Hi, this row

      Visual Basic
      AddHandler tooltipController.GetActiveObjectInfo, AddressOf tooltipController_GetActiveObjectInfo

      return me the following error: "'GetActiveObjectInfo' is not a 'ToolTipController' event.
      In fact, the tootipController object hasn't the event listed. It is defined in this way

      Visual Basic
      tooltipController = New ToolTipController()

      What's the problem?

      Anatol (DevExpress) 7 years ago

        Please ensure that you have used the ToolTipController class from the DevExpress.Utils namespace. Here is our documentation for this event: ToolTipController.GetActiveObjectInfo. If this does not help, please provide a sample project demonstrating the issue.

          Thanks a lot!!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.