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.
Show tooltip with property value for ListView grid cells
Answers approved by DevExpress Support
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 BasicImports 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.
Hi, this row
Visual BasicAddHandler 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 BasictooltipController = New ToolTipController()
What's the problem?
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.