Controls - Do you use a ToolTip to show the full text of hidden ListView data?

Updated by Brady Stroud [SSW] 1 year ago. See history

123

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

Image

❌ Figure: Bad example - Users can't see all the text and the ListView doesn't use a Tooltip

Image

✅ 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, "");
}
}
}
}
acknowledgements
related rules