36

I am using a ListView with a few fixed-size columns.

The text in the rows may be too large to fit in the column, so I would like to make it so that when the user hovers over the ListViewItem, it shows a tooltip with more text.

I tried setting the ToolTipText property of the ListViewItem:

ListViewItem iListView = new ListViewItem("add");

iListView.ToolTipText = "Add Expanded";
myListView.Items.Add(iListView);

Unfortunately, it didn't seem to work. How can I get ListViewItems to show ToolTips?

jrh
  • 405
  • 2
  • 10
  • 29
Gaddigesh
  • 1,953
  • 8
  • 30
  • 41

2 Answers2

61

Set the ListView's ShowItemToolTips property to true.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    It appears the tooltips also have a character limit when trying to display really long strings. There are several solutions that circumvent the 259 column limit for displaying text within the ListView (e.g. http://stackoverflow.com/questions/5559704/net-listview-max-number-of-characters-or-maximum-column-width-possible-to-ov) or you can let the user copy-paste the selected lines. – valsidalv Nov 25 '13 at 16:01
  • 1
    This works only for items' subitems which text doesn't fit in column. But when you set `ToolTipText` property on `ListViewItem`, tooltip is gonna show always, but that refers only to first subitem. – gangus Jan 31 '20 at 14:17
7

Use ListViewItem.ToolTipText Property

// Declare the ListView.
private ListView ListViewWithToolTips;
private void InitializeItemsWithToolTips()
{

    // Construct and set the View property of the ListView.
    ListViewWithToolTips = new ListView();
    ListViewWithToolTips.Width = 200;
    ListViewWithToolTips.View = View.List;

    // Show item tooltips.
    ListViewWithToolTips.ShowItemToolTips = true;

    // Create items with a tooltip.
    ListViewItem item1WithToolTip = new ListViewItem("Item with a tooltip");
    item1WithToolTip.ToolTipText = "This is the item tooltip.";
    ListViewItem item2WithToolTip = new ListViewItem("Second item with a tooltip");
    item2WithToolTip.ToolTipText = "A different tooltip for this item.";

    // Create an item without a tooltip.
    ListViewItem itemWithoutToolTip = new ListViewItem("Item without tooltip.");

    // Add the items to the ListView.
    ListViewWithToolTips.Items.AddRange(new ListViewItem[]{item1WithToolTip, 
        item2WithToolTip, itemWithoutToolTip} );

    // Add the ListView to the form.
    this.Controls.Add(ListViewWithToolTips);
    this.Controls.Add(button1);
}
KMån
  • 9,896
  • 2
  • 31
  • 41
  • @SLaks: Thats a snip from the link I added; just that I should have added more lines. Thanks for pointing out. – KMån Apr 28 '10 at 16:23