Help with displaing field definition when placing cursor on a row of a listbox using VB.NET

Hi,

When I place the cursor on a row of my listbox I need to display the defnition of the field, for example If I place my cursor on a row containing TV, would like too see a tooltip with the word television.

Thanks,

Victor
vcharlesAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi Victor;

Something like the following should work.
Public Class Form1

    Dim ttc1 As New ToolTip()

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        '' Items to be added to the ListBox
        Dim items As New List(Of MyListBoxItem)() From {New MyListBoxItem With {.Item = "NSN", .ToolTipValue = "NSN Value Here"},
            New MyListBoxItem With {.Item = "NSC", .ToolTipValue = "NSC Value Here"},
            New MyListBoxItem With {.Item = "FIF", .ToolTipValue = "FIF Value Here"}
        }

        ListBox1.DataSource = items
        ListBox1.DisplayMember = "Item"
        ListBox1.ValueMember = "ToolTipValue"

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ttc1.SetToolTip(ListBox1, "Select an Item to see Description")
        ttc1.ShowAlways = True
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        ttc1.SetToolTip(ListBox1, ListBox1.SelectedValue.ToString)
    End Sub

End Class

Public Class MyListBoxItem
    Public Property Item As String
    Public Property ToolTipValue As String

    Public Overrides Function ToString() As String
        Return Item
    End Function
End Class

Open in new window

0
 
Fernando SotoRetiredCommented:
Hi Victor;

So where are you getting the "definition" to display in the tooltip?
0
 
vcharlesAuthor Commented:
Hi Fernando,

I would like the hardcode the definition.

Thanks,

Victor
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
vcharlesAuthor Commented:
Hi Fernando,

Thanks for the code. How do you modify it to work when I place the mouse on the row? not select the row.

Thanks,

Victor
0
 
Fernando SotoRetiredCommented:
You can't because the ToolTip control is attached to a control and not to a collection.
0
 
vcharlesAuthor Commented:
Ok. Thanks.
0
 
Fernando SotoRetiredCommented:
Not a problem Victor, glad to help.
0
All Courses

From novice to tech pro — start learning today.