Home
Controls - Do you use a ToolTip to show the full text of hidden ListView data?
  v2.0 Posted at 24/02/2017 1:35 AM by Tiago Araujo

​When you can't see all the text for an item in a ListView you need to expose the full text via a ToolTip.

ListView control without Tooltip.
Figure: Bad Example - Users can't see all the text and the ListView doesn't use a Tooltip
ListView control with Tooltip.
Figure: Good Example - Users can't see all the text, but the ListView shows all the text via a Tooltip
The code to do this is:

private ListViewItem hoveredItem;
private void listView1_MouseMove(object sender, MouseEventArgs e)
{
ListView lv = (ListView) sender;
ListViewItem item = lv.GetItemAt(e.X, e.Y);
int columnIndex = 1;
if (item != hoveredItem)
{
hoveredItem = item;
if (item == null)
{
toolTip1.SetToolTip(lv, "");
}
else
{
// Make sure the mouse hovered row has the subitem
if (item.SubItems.Count > columnIndex)
{
toolTip1.SetToolTip(lv, item.SubItems[columnIndex].Text);
}
else
{
toolTip1.SetToolTip(lv,"");
}
}
}
}​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments: