This is a migrated thread and some comments may be shown as answers.

Tooltiptext for listview item

14 Answers 905 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Pixie
Top achievements
Rank 1
Pixie asked on 25 Apr 2019, 10:32 PM

I'm trying to set the tooltiptext for a radListView item. I add the item to the listview as follows:
Dim myitem As New ListViewDataItem("Text to display")
myitem(1) = "Text to use for tooltip"
lvwAttach.Items.Add(myitem)

 

I 'm using TooTipTextNeeded to set the tooltip text:

Private Sub lvwAttach_ToolTipTextNeeded(sender As Object, e As ToolTipTextNeededEventArgs) Handles lvwAttach.ToolTipTextNeeded
        Dim item As SimpleListViewVisualItem = TryCast(sender, SimpleListViewVisualItem)
        If item IsNot Nothing Then
            e.ToolTipText = item.Text
        End If
    End Sub

This shows the item's text as the tooltip but I want to show the text from the 1st subitem. How do I get the text for the 1st subitem from the SimpleListViewVisualItem object?

14 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Apr 2019, 11:27 AM
Hello, Pixie,    

The ToolTipTextNeeded event is the appropriate place to specify what text to be used for the tool-tip. if you need to store the tool-tip text inside the ListViewDataItem and then use it in the ToolTipTextNeeded, feel free to use the Tag property. I have prepared a sample code snippet: 

Sub New()
    InitializeComponent()
 
    Dim myitem As New ListViewDataItem("Text to display")
    myitem.Tag  = "Text to use for tooltip"
    Me.RadListView1.Items.Add(myitem)
End Sub
 
Private Sub lvwAttach_ToolTipTextNeeded(sender As Object, e As ToolTipTextNeededEventArgs) Handles RadListView1.ToolTipTextNeeded
    Dim item As SimpleListViewVisualItem = TryCast(sender, SimpleListViewVisualItem)
    If item IsNot Nothing Then
        e.ToolTipText = item.Data.tag
    End If
End Sub




I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Pixie
Top achievements
Rank 1
answered on 28 Apr 2019, 09:37 PM

Hi Dess

I'm already using the tag for something else, which is why I wanted to use a subitem. Is there a way to get the subitem value from within the ToolTipTextNeeded event?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Apr 2019, 09:56 AM
Hello, Pixie,     

I would like to note that when in DetailsView, RadListView displays columns. The columns are stored in a collection that is accessible through the Columns property. Columns can be added to RadListView using one of the three overloads of the Add method. Each column must have a unique name because columns are distinguished by their Name property. You can set cell values to the items of RadListView using their indexers. The keys can be either the index of the column, the name of the column, or the column itself. However, it is important that you add the item to the control prior assigning its cell's values, so it will have its cells schema

Sub New()
    InitializeComponent()
 
    Dim myitem As New ListViewDataItem("Text to display")
    Me.RadListView1.Columns.Add("Column1")
    Me.RadListView1.Items.Add(myitem)
    myitem(1)  = "Text to use for tooltip"
     
End Sub
 
Private Sub lvwAttach_ToolTipTextNeeded(sender As Object, e As ToolTipTextNeededEventArgs) Handles RadListView1.ToolTipTextNeeded
    Dim item As SimpleListViewVisualItem = TryCast(sender, SimpleListViewVisualItem)
    If item IsNot Nothing Then
        e.ToolTipText = item.Data(1)
    End If
End Sub

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Rahe
Top achievements
Rank 1
answered on 15 Sep 2020, 09:37 AM

Hi,

is it possible to do the same for a RadListControl?

As what do I need to define "item"? If I declare it as SimpleListViewVisualItem, "item" is always "nothing"

 

regards,

Rahe

0
Nadya | Tech Support Engineer
Telerik team
answered on 17 Sep 2020, 02:54 PM

Hello, Rahe,

In RadListControl you can add DescriptionTextListDataItem or RadListDataItem to the Items collection. Please check the following article: https://docs.telerik.com/devtools/winforms/controls/dropdown-listcontrol-and-checkeddropdownlist/listcontrol/populating-with-data/adding-items-programmatically 

Respectively, in the ToolTipTextNeeded event, you should use RadListElement. Please refer to the same example adopted for RadListControl:

Public Partial Class RadForm1
    Inherits Telerik.WinControls.UI.RadForm
    Private myitem As RadListDataItem
    Public Sub New()
        InitializeComponent()
        Dim spyForm As RadControlSpyForm = New RadControlSpyForm()
        spyForm.Show()
        myitem = New RadListDataItem("Text to display")
        Me.radListControl.Items.Add(myitem)
        myitem.Text = "Text to use for tooltip"
        radListControl.ToolTipTextNeeded += AddressOf Me.RadListControl1_ToolTipTextNeeded
    End Sub

    Private Sub RadListControl1_ToolTipTextNeeded(ByVal sender As Object, ByVal e As ToolTipTextNeededEventArgs)
        Dim item As RadListElement = TryCast(sender, RadListElement)
        If item IsNot Nothing Then e.ToolTipText = myitem.Text
    End Sub
End Class

I hope this helps. Let me know if you have any other questions.

Regards,
Nadya
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
Rahe
Top achievements
Rank 1
answered on 18 Sep 2020, 08:54 AM
[quote]Nadya said:

Hello, Rahe,

In RadListControl you can add DescriptionTextListDataItem or RadListDataItem to the Items collection. Please check the following article: https://docs.telerik.com/devtools/winforms/controls/dropdown-listcontrol-and-checkeddropdownlist/listcontrol/populating-with-data/adding-items-programmatically 

Respectively, in the ToolTipTextNeeded event, you should use RadListElement. Please refer to the same example adopted for RadListControl:

Public Partial Class RadForm1
    Inherits Telerik.WinControls.UI.RadForm
    Private myitem As RadListDataItem
    Public Sub New()
        InitializeComponent()
        Dim spyForm As RadControlSpyForm = New RadControlSpyForm()
        spyForm.Show()
        myitem = New RadListDataItem("Text to display")
        Me.radListControl.Items.Add(myitem)
        myitem.Text = "Text to use for tooltip"
        radListControl.ToolTipTextNeeded += AddressOf Me.RadListControl1_ToolTipTextNeeded
    End Sub

    Private Sub RadListControl1_ToolTipTextNeeded(ByVal sender As Object, ByVal e As ToolTipTextNeededEventArgs)
        Dim item As RadListElement = TryCast(sender, RadListElement)
        If item IsNot Nothing Then e.ToolTipText = myitem.Text
    End Sub
End Class

I hope this helps. Let me know if you have any other questions.

Regards,
Nadya
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

[/quote]

 

Hi Nadya,

thanks for the feedback. Unfortunately it does not work for me. The Tooltip text will also be shown as display text. And the ToolTip will be shown always, not only when the cursor is above the Element (see picture for details). Below is my test code:.

 

regards

Rahe

Public Class RadForm1
    Inherits RadForm
    Private myitem As RadListDataItem
 
    Public Sub New()
        InitializeComponent()
        'Dim spyForm As RadControlSpyForm = New RadControlSpyForm()
        'spyForm.Show()
        myitem = New RadListDataItem("Text to display")
        Me.RadListControl1.Items.Add(myitem)
        myitem.Text = "Text to use for tooltip"
        'RadListControl1.ToolTipTextNeeded += AddressOf Me.RadListControl1_ToolTipTextNeeded
    End Sub
 
    Private Sub RadListControl1_ToolTipTextNeeded(ByVal sender As Object, ByVal e As ToolTipTextNeededEventArgs) Handles RadListControl1.ToolTipTextNeeded
        Dim item As RadListElement = TryCast(sender, RadListElement)
        If item IsNot Nothing Then
            e.ToolTipText = myitem.Text
        End If
    End Sub

 

0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Sep 2020, 01:12 PM

Hello, Rahe,

By design, the Tooltip represents a small rectangular window that displays a brief description when the user hovers over control or an element. All controls have the ToolTipTextNeeded event which can be used for dynamically setting the text of the tooltips.

If I understand you correctly, you want to display a tooltip always, not only when the cursor is above the RadListElement. If this is the behavior you want to achieve you can use one of the overloads of the Tooltip.Show method in the ToolTipTextNeeded event as shown below:

    Private Sub RadListControl1_ToolTipTextNeeded(ByVal sender As Object, ByVal e As ToolTipTextNeededEventArgs) Handles RadListControl1.ToolTipTextNeeded
        Dim item As RadListElement = TryCast(sender, RadListElement)
        If item IsNot Nothing Then
            ' e.ToolTipText = myitem.Text
            e.ToolTip.Show(myitem.Text, Me.RadListControl1)
        End If
    End Sub

I hope this helps. If you need further assistance please let me know.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Rahe
Top achievements
Rank 1
answered on 29 Sep 2020, 09:28 AM
Hello Nadya,

sorry for delay of my feedback!


NO, I only want to display a tooltip when hovering over an element. When hovering over the element it shows "Text to use for tooltip" but when I am hovering over the empty space of the RadListControl, it is still displays the text. I don't want to display a tooltip always only when hovering over the element.

 

Also, the element itself shows the wrong text. It should display "Text to display" but it shows "Text to use for tooltip"
In your attached gif, the text of the element is "Text to use for tooltip" so it is the wrong text, too! The element should display "Text to display" and the tooltip of the element should display "Text to use for tooltip". Please see attached pictures for details.

 

Regards,

Rahe
0
Nadya | Tech Support Engineer
Telerik team
answered on 29 Sep 2020, 01:23 PM

Hello, Rahe,

You can set any text that you want to the visual item and the tooltip. The following code snippet displays the desired text as per your requirement:

Public Class RadForm1
    Sub New()
        InitializeComponent()
        Dim myitem As RadListDataItem
        myitem = New RadListDataItem("Text to display")
        Me.RadListControl1.Items.Add(myitem)
        myitem.Text = "Text to display"
        AddHandler RadListControl1.ToolTipTextNeeded, AddressOf Me.RadListControl1_ToolTipTextNeeded
    End Sub

    Private Sub RadListControl1_ToolTipTextNeeded(sender As Object, e As ToolTipTextNeededEventArgs)
        Dim item As RadListElement = TryCast(sender, RadListElement)
        If item IsNot Nothing Then e.ToolTipText = "Text to use for tooltip"
    End Sub
End Class

I hope this helps. Should you have further questions please let me know.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Rahe
Top achievements
Rank 1
answered on 29 Sep 2020, 04:41 PM

Hello Nadya,

this does not work as espected. When hovering the list element, no tooltip shows. When hovering the empty area of the radList, the tooltip shows. Now the tooltip also shows when hovering the list element. Please see attached GIF for the demonstration. This is my code:

Public Class Form1
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim myitem As RadListDataItem
        myitem = New RadListDataItem("Text to display")
        Me.RadListControl1.Items.Add(myitem)
        myitem.Text = "Text to display"
        AddHandler RadListControl1.ToolTipTextNeeded, AddressOf Me.RadListControl1_ToolTipTextNeeded
    End Sub
 
    Private Sub RadListControl1_ToolTipTextNeeded(sender As Object, e As Telerik.WinControls.ToolTipTextNeededEventArgs) Handles RadListControl1.ToolTipTextNeeded
        Dim item As RadListElement = TryCast(sender, RadListElement)
        If item IsNot Nothing Then e.ToolTipText = "Text to use for tooltip"
    End Sub
End Class
0
Nadya | Tech Support Engineer
Telerik team
answered on 30 Sep 2020, 04:05 PM

Hello, Rahe,

If your requirement is to show the screen tip only for the visual items you should use RadListVisualItem instead of RadListElement in the ScreentipNeeded event. Please refer to the updated code snippet:

Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim myitem As RadListDataItem
    myitem = New RadListDataItem("Text to display")
    Me.RadListControl1.Items.Add(myitem)
    myitem.Text = "Text to display"
    AddHandler RadListControl1.ToolTipTextNeeded, AddressOf Me.RadListControl1_ToolTipTextNeeded
End Sub
Private Sub RadListControl1_ToolTipTextNeeded(sender As Object, e As Telerik.WinControls.ToolTipTextNeededEventArgs) Handles RadListControl1.ToolTipTextNeeded
    Dim item As RadListVisualItem = TryCast(sender, RadListVisualItem)
    If item IsNot Nothing Then e.ToolTipText = "Text to use for tooltip"
End Sub

I hope this helps.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Rahe
Top achievements
Rank 1
answered on 30 Sep 2020, 04:52 PM

Hello Nadya,

now it works as expected, thank you!

If possible, I would like to use the .Tag property of the RadListDataItem to store the Tooltip text, like this:

myitem = New RadListDataItem("Text to display")
Me.RadListControl1.Items.Add(myitem)
myitem.Text = "Text to display"
myitem.Tag = "Text to use for tooltip"

Do you have an idea how I can access the properties of the RadListDataItem in the ToolTipTextNeeded sub?

The following code obviously does not work, possibly because "item" is not a RadListDataItem but a RadListVisualItem.

Private Sub RadListControl1_ToolTipTextNeeded(sender As Object, e As Telerik.WinControls.ToolTipTextNeededEventArgs) Handles RadListControl1.ToolTipTextNeeded
   Dim item As RadListVisualItem = TryCast(sender, RadListVisualItem)
   If item IsNot Nothing Then e.ToolTipText = "item.Tag"
End Sub

Any idea how to solve this?

 

regards,

Rahe

0
Nadya | Tech Support Engineer
Telerik team
answered on 02 Oct 2020, 02:49 PM

Hello, Rahe,

In order to use the Tag property of the data item in the ToolTipTextNeeded event, you should access the data item through RadListVisualItem.Data property. Please refer to the updated code snippet :

Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim myitem As RadListDataItem
        myitem = New RadListDataItem("Text to display")
        Me.RadListControl1.Items.Add(myitem)
        myitem.Text = "Text to display"
        myitem.Tag = "Text to use for tooltip"
        AddHandler RadListControl1.ToolTipTextNeeded, AddressOf Me.RadListControl1_ToolTipTextNeeded
    End Sub
    Private Sub RadListControl1_ToolTipTextNeeded(sender As Object, e As Telerik.WinControls.ToolTipTextNeededEventArgs) Handles RadListControl1.ToolTipTextNeeded
        Dim item As RadListVisualItem = TryCast(sender, RadListVisualItem)
        If item IsNot Nothing Then e.ToolTipText = item.Data.Tag
    End Sub

Please let me know if you need further assistance.

Regards,
Nadya
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
Rahe
Top achievements
Rank 1
answered on 02 Oct 2020, 03:59 PM

Hello Nadya,

somehow I missed, that the  "Data" property holds all information of the RadListDataItem. Now everything works as required.

Thank you very much for your ongoing support!

regards,

Rahe

Tags
ListView
Asked by
Pixie
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Pixie
Top achievements
Rank 1
Rahe
Top achievements
Rank 1
Nadya | Tech Support Engineer
Telerik team
Share this question
or