Reputation: 938
I'm adding a ToolTip to a ListViewItem. However, the ToolTip only shows up when the user hovers over the first cell in the row to which the ToolTip has been applied.
MyListViewItem.ToolTipText = "Important Message"
The only other code I have related to ToolTips is this:
MyListView.ShowItemToolTips = True
Any idea how I can make the ToolTip show up on a specific cell in a row, or even the entire row? Thanks.
Upvotes: 0
Views: 4694
Reputation: 2086
If you want a non-wrapper answer unlike the dup mentioned, try this:
The listview FullrowSelect property must be true. Next you need to store the tips for each subitem, I do this inside the subitem tag property. What you want to do, is on the listview mousemove event, you grab the item under the mouse, get it's subitem, and use that tip.
This simple example shows you how to get that subitem tooltip, you can just hack this a bit to suit your needs.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lvw.ShowItemToolTips = True
lvw.Columns.Add("Column A")
lvw.Columns.Add("Column B")
lvw.Columns.Add("Column C")
lvw.Items.Add(New ListViewItem(New String() {"Colors", "Green", "Blue"}))
lvw.Items(0).SubItems(0).Tag = "See the other columns"
lvw.Items(0).SubItems(1).Tag = "Like grass"
lvw.Items(0).SubItems(2).Tag = "Like the sky"
End Sub
Function GetItemTip(ByVal list As ListView, ByVal e As System.Windows.Forms.MouseEventArgs) As String
Dim item As ListViewItem = list.GetItemAt(e.X, e.Y)
If Not IsNothing(item) Then
Dim si As ListViewItem.ListViewSubItem
si = item.GetSubItemAt(e.X, e.Y)
If Not IsNothing(si) Then
Return si.Tag.ToString
Else
Return ""
End If
Else
Return ""
End If
End Function
Private Sub lvw_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lvw.MouseMove
Me.Text = GetItemTip(CType(sender, ListView), e)
End Sub
Upvotes: 1