ListView Tooltips for SubItems
I don't say much about my .NET work here,
sometimes because the nature of that work is proprietary, but usually because
there's so much about .NET already on the web that it'd just be redundant. I had
a hard time finding out exactly how .NET 2.0 supported tooltips for ListView
subitems, though, so I thought I'd put a small blurb on the web for the benefit
of others...
The ListView control in .NET 2.0 offers a number
of improvements, one of which is a new property called ShowItemTooltips.
When true, this property allows a tooltip to be displayed when the user mouses
over an item in the ListView. The text displayed for the ListViewItem can be set
by its ToolTipText
property.All very nice, but I had an
application where I was displaying a table of data (a ListView in "details"
mode) where some of the data could quite naturally appear longer than the column
width allowed. A tooltip containing the subitem text seemed just the ticket, and
according to the documentation
for ShowItemTooltips, "When
FullRowSelect is set to true, ToolTips for a ListViewItem.ListViewSubItem will
not be shown; only the ToolTip for the parent ListViewItem will
display."Tantalizing: Microsoft
implies that tooltips for subitems are supported
somehow.
Browsing ListViewSubItem
members, however, shows no ToolTipText property similar to that for
ListViewItem. So what is Microsoft's documentation really
saying?A little experimentation turned
up the answer. If you set ShowItemTooltips for the ListView control in "details"
mode and do nothing else, the ListView control will automatically provide
tooltips for items and subitems that exceed their column's widths. This turns
out to work even if the FullRowSelect property is set to true. If ToolTipText
has been set for a ListViewItem and FullRowSelect is true, then the tooltip will
appear for the whole row; that's the case where tooltips won't be displayed for
subitems.Note that, for subitems, the
tooltip text will be the same as the subitem text. In my case, that's exactly
what I wanted, and I think it's a sensible default behavior. I can imagine
applications, though, where it might be handy to have a ToolTipText property on
ListViewSubItems, allowing the tooltip to differ from the subitem text. If
that's what you need, you might have to look elsewhere
until the next iteration of the .NET framework.
Posted: Sat - April 15, 2006 at 10:34 AM