views:

402

answers:

1

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.

+1  A: 

Hi Louise. 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
Wez
This code just changes the name of the form, it doesn't make a tooltip show up: Me.Text = GetItemTip(CType(sender, ListView), e)
Louise
I know, as I said it shows how to support tips for sub items, and that you just have to hack around with it to suit your needs. Maybe use a tooltip control on the listview :)
Wez