Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Tooltip on a listview Item

Posted on 2004-09-16
3
Medium Priority
?
452 Views
Last Modified: 2010-05-18
I am loading a list view with reports ,I want to display a tooltip as the mouse pointer hovers over an listitem ,can this be done and how?
Cheers T
0
Comment
Question by:visualbasic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
graye earned 200 total points
ID: 12077769
As you've probably figured out... there is no "hover event" for the ListViewItems objects.   So, you have to make one "by hand".

In this example below, the tooltip data comes from a dataTable... but other than that one oddity, it's pretty straight forward.

    Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
        Dim lvi As ListViewItem
        Dim drs() As DataRow
        Static last_lvi As Integer = -1

        ' this is a poor man's "ListItem_MouseHover event"
        lvi = ListView1.GetItemAt(e.X, e.Y)
        If Not IsNothing(lvi) Then
            If lvi.Index <> last_lvi Then
                drs = dt.Select("PC_Name='" & lvi.Text & "'")
                If UBound(drs) >= 0 AndAlso drs(0)("ID") <> "" Then
                    ToolTip1.SetToolTip(Me.ListView1, "Comment: " & drs(0)("PC_Comment") & vbCr & "User: " & drs(0)("UserName") & vbCr & "Model: " & drs(0)("PC_Model") & vbCr & "OS: " & drs(0)("OS") & vbCr & "Bldg: " & drs(0)("Bldg") & vbCr & "Div: " & drs(0)("Division"))
                Else
                    ToolTip1.SetToolTip(Me.ListView1, "No Data")
                End If
            End If
            last_lvi = lvi.Index
        Else
            ToolTip1.SetToolTip(Me.ListView1, "")
            last_lvi = -1
        End If

    End Sub
0
 
LVL 16

Expert Comment

by:RobertRFreeman
ID: 12079010
Unfortunately, list items are not controls and there is no supplied hit test, so if you want, you can use the following solution.
I believe the list item height must be fixed to use this:
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20897372.html

The datagrid does supply a hittest for tooltips.
See this link for instructions:
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q843q
0
 
LVL 41

Expert Comment

by:graye
ID: 12080175
Hummm... I realized that my example lacked a great deal of explaination!

I set a tooltip control to active on the entire ListView object... then programmatically change the contents of the tooltip's data to be displayed based upon which ever ListViewItem is currently selected.   So the example above does that... it detects which ListViewItem is current and (in my somewhat strange example) queries a database to populate the contents of the ToolTip.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question