ToolTipTextNeeded event not being raised

4 posts, 1 answers
  1. Taibe
    Taibe avatar
    8 posts
    Member since:
    Jun 2012

    Posted 25 May 2012 Link to this post

    I have a custom cell element within a RadGridView. The custom cell is a RadGridView as well. I would like to show tooltips on some of the cells in the inner RadGridView. I am able to do this successfully by setting the cell's tooltiptext property in the Cell_formatting event, however, I need the tooltip to show for longer and I also need to format it. So, I tried creating an event handler for the ToolTipTextNeeded event and displaying a Windows.Forms tooltip there, but the event is not being raised at all. Please see my code below. If anyone can point out what I'm doing wrong, I'd really appreciate it.
    Imports Telerik.WinControls.UI
     
    Public Class ClaimAdjustmentsCellElement
        Inherits GridDataCellElement
        Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement)
            MyBase.New(column, row)
        End Sub
     
        Private _radGridView As RadGridView
        Private tip As ToolTip = New ToolTip With {.BackColor = Color.AliceBlue, .ToolTipIcon = ToolTipIcon.Info, .InitialDelay = 500, .ShowAlways = True}
     
        Protected Overrides Sub CreateChildElements()
            MyBase.CreateChildElements()
     
            _radGridView = New RadGridView()
            With _radGridView
                .Dock = DockStyle.Fill
                .ReadOnly = True
                .ShowFilteringRow = False
                .ShowGroupPanel = False
                .ShowColumnHeaders = True
                .ShowRowHeaderColumn = False
                .ShowNoDataText = False
                .AutoScroll = True
                .AutoSizeRows = True
                .SelectionMode = GridViewSelectionMode.CellSelect
                .AutoGenerateColumns = False
                .ShowItemToolTips = True
            End With
     
            Dim GroupCodeColumn As New GridViewTextBoxColumn("Group.Code") With {.HeaderText = "GC", .Width = 25}
            Dim ReasonColumn As New GridViewTextBoxColumn("Reason.Code") With {.HeaderText = "RSN", .Width = 35}
            Dim AmountColumn As New GridViewDecimalColumn("Amt") With {.HeaderText = "AMT", .FormatString = "{0:c}", .Width = 75}
            Dim IsDenialColumn As New GridViewCheckBoxColumn("Reason.IsDenial") With {.HeaderText = "Denial", .Width = 65}
            _radGridView.Columns.AddRange(GroupCodeColumn, ReasonColumn, DescrColumn, AmountColumn, IsDenialColumn)
     
            AddHandler _radGridView.CellFormatting, AddressOf _radGridView_CellFormatting
            AddHandler _radGridView.ToolTipTextNeeded, AddressOf _radGridView_TooltipTextNeeded
     
            Me.Children.Add(_radGridView.GridViewElement)
        End Sub
     
        Protected Overrides Sub SetContentCore(value As Object)
            If value IsNot Nothing AndAlso (Not value.Equals(DBNull.Value)) Then
                _radGridView.DataSource = value           
            End If
        End Sub
     
        Private Sub _radGridView_CellFormatting(sender As Object, e As CellFormattingEventArgs)
            'e.CellElement.ToolTipText = ""
            e.CellElement.DrawFill = False
            If e.CellElement.IsSelected Then
                e.CellElement.DrawBorder = False
            Else
                e.CellElement.DrawBorder = True
            End If
     
            'Dim oClaimAdj As ClaimAdjustment = TryCast(e.Row.DataBoundItem, ClaimAdjustment)
            'Select Case e.Column.Name
            '    Case "Group.Code"
            '        If oClaimAdj IsNot Nothing AndAlso oClaimAdj.Group IsNot Nothing Then
            '            e.CellElement.ToolTipText = oClaimAdj.Group.Description
            '        End If
            '    Case "Reason.Code"
            '        If oClaimAdj IsNot Nothing AndAlso oClaimAdj.Reason IsNot Nothing Then
            '            e.CellElement.ToolTipText = oClaimAdj.Reason.Description
            '        End If
            'End Select
     
        End Sub
     
        Protected Overrides ReadOnly Property ThemeEffectiveType As System.Type
            Get
                Return GetType(GridDataCellElement)
            End Get
        End Property
        Public Overrides Function IsCompatible(data As Telerik.WinControls.UI.GridViewColumn, context As Object) As Boolean
            Return TypeOf (data) Is ClaimAdjustmentColumn AndAlso TypeOf (context) Is GridDataRowElement
        End Function
     
        Private Sub _radGridView_TooltipTextNeeded(sender As Object, e As Telerik.WinControls.ToolTipTextNeededEventArgs)
            Try
                Dim cell As GridDataCellElement = TryCast(sender, GridDataCellElement)
                If cell IsNot Nothing And tip IsNot Nothing Then
                    Dim oClaimAdj As ClaimAdjustment = TryCast(cell.RowElement.Data.DataBoundItem, ClaimAdjustment)
                    Dim tipText As String = ""
                    Select Case cell.ColumnInfo.FieldName
                        Case "Group.Code"
                            If oClaimAdj IsNot Nothing AndAlso oClaimAdj.Group IsNot Nothing Then
                                tipText = oClaimAdj.Group.Description
                            End If
                        Case "Reason.Code"
                            If oClaimAdj IsNot Nothing AndAlso oClaimAdj.Reason IsNot Nothing Then
                                tipText = oClaimAdj.Reason.Description
                            End If
                    End Select
                    If Not String.IsNullOrEmpty(tipText) Then
                        With tip
                            .Active = False
                            .AutoPopDelay = 30000
                            .SetToolTip(_radGridView, tipText)
                            .Active = True
                        End With
                    End If
     
                End If
            Catch ex As Exception
                throw
            End Try
            
        End Sub
     
    End Class

  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 29 May 2012 Link to this post

    Hello Taibe,

    Thank you for the question.

    The ToolTipTextNeeded event is not fired for the RadGridView instance that you have, because you are inserting just the element of the control, rather than the control itself:

    Me.Children.Add(_radGridView.GridViewElement)

    Instead, you have to insert the RadGridView control instance as shown below. This will get your ToolTipTextNeeded event fired:
    Dim host As RadHostItem = New RadHostItem(_radGridView)
    Me.Children.Add(host)

    Generally speaking, we would recommend agains using RadGridView or other complex controls in the cells of RadGridView, because during a scrolling operation in the main RadGridView, you may experience decreased performance.

    I am attaching a sample project which demonstrates how tooltips are show for the inner grid. I hope this helps.

    Regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. Taibe
    Taibe avatar
    8 posts
    Member since:
    Jun 2012

    Posted 29 May 2012 Link to this post

    Thank you, Nikolay. Using your solution, I was able to display the tooltips as I wished. However, adding a RadGridView instead of a GridViewElement did degrade the performance of my outer grid and caused some funny display issues. Therefore, I decided to forgo the fancy tooltips and just set the e.cellElement.ToolTipText property in the Cell_Formatting event as I had been doing previously.
  4. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 01 Jun 2012 Link to this post

    Hi Taibe,

    Indeed, adding a control (which is a heavy object) in the hierarchy of elements would result in a heavier structure as a whole. Therefore, if the performance does not satisfy your needs, I would also recommend that you continue using the standard tooltips in the CellFormatting event. 

    Let us know if you have additional questions.

    Regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top