How to set tooltip for a ListviewItem

前端 未结 2 547
慢半拍i
慢半拍i 2020-12-06 09:30

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

相关标签:
2条回答
  • 2020-12-06 09:53

    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);
    }
    
    0 讨论(0)
  • 2020-12-06 10:01

    Set the ListView's ShowItemToolTips property to true.

    0 讨论(0)
提交回复
热议问题