Click here to Skip to main content
13,298,481 members (59,811 online)
Click here to Skip to main content
Add your own
alternative version


64 bookmarked
Posted 21 Oct 2003

ListView with Item-Hover Event

, 21 Oct 2003
Rate this:
Please Sign up or sign in to vote.
An article to display tooltips over listview items and subitems.

ListView with ItemHover event


The ListView used by Microsoft Windows Explorer shows tool tips when a particular item is partly visible, saving the user the task of scrolling or resizing. Keeping this as my goal, I set out to achieve the same effect.

All controls that derive from System.Windows.Forms.Control have a MouseHover event. Most of the time this event is used for displaying additional or extended information about the control. For controls like the ListView, which displays different data, this event although useful, leaves the programmer aching for more information. The details about the items within the control are elusive to get at.

While there are events like ItemCheck, ItemActivate, ItemDrag, there isn't any event like the ItemHover. A little investigation with the Spy++ tool and digging through MSDN revealed that every ListView maintains an internal tool tip. This tool tip sends a message in the form of a WM_NOTIFY handler whenever it needs text from the ListView. I ended up trapping this message and exposing it off as an ItemHover event. The client can then consume this event and display additional information as needed or display a tool tip as shown in figure.

However, I quickly found out that it is very distracting after a while to see a series of tool tips flickering around on the screen. This happens because the ListView gets the message when the mouse hovers over its items, but it doesn't know whether the item or sub item is visible. It would be nice to add that information as an event argument. That was achieved by comparing the string width to the actual displayed rectangle of the item or sub item.

Armed with this information, the client can intelligently display more information about the partially hidden item, as seems fit. I tried showing it in a tool tip, you can even show it on a StatusBar or maybe the more courageous can display a Balloon Tip.

Longer lines of text wouldn't wrap around to display in the tool tip. For the purpose of the sample I wrote a small procedure to wrap those lines of text into multiple lines, by inserting the new line character. You can change this logic to fit your needs. Enjoy the code and any feedback is appreciated.

Using the code

A small example of how to use the control has been included in the form. This control works properly when the ListView is in Report mode. I haven't tested it with any other mode.


The ListView can also be made to display its internal tool tip by setting its style to LVS_EX_INFOTIP. However, according to MSDN, the ListView needs to have the LVS_FULL_ROWSELECT style set too for sub items. Hence I experimented with this method.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Ramesh Shrivastav
Web Developer
United States United States
Ramesh is very much into Microsoft technologies, and silently marvels at the power of Windows SDK.
He juggles his time between his family, work and his computer.

You may also be interested in...

Comments and Discussions

GeneralDoes not work at all Pin
ReorX1-Aug-08 2:56
memberReorX1-Aug-08 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 22 Oct 2003
Article Copyright 2003 by Ramesh Shrivastav
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid