[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4955
  • Last Modified:

Windows ListView subitems tooltip not working

I have list view with fullrowselect property true.
I set ListView.ShowItemToolTips = true;
I want to give tooltip for 1 subitem.
There is no tooltiptext property for subitems.
How can I do this?
0
rishaan
Asked:
rishaan
  • 4
  • 4
1 Solution
 
Wayne Taylor (webtubbs)AstronautCommented:
Hi rishaan,

You'll need to use the MouseMove() event of the listview to show tooltips from the subitems. See the below code for an example.

Regards,

Wayne
public class Form1
{
    
    private void Form1_Load(object sender, System.EventArgs e)
    {
        for (int i = 1; i <= 5; i++) {
            ListViewItem lvi = ListView1.Items.Add("Item" + i);
            lvi.ToolTipText = lvi.Text;
            for (int s = 1; s <= 5; s++) {
                ListViewItem.ListViewSubItem lvsi = lvi.SubItems.Add("Item" + i + " - " + "SubItem" + s);
                lvsi.Tag = lvsi.Text;
            }
        }
    }
    
    private void ListView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        ListViewHitTestInfo ht = ListView1.HitTest(e.Location);
        if ((ht.SubItem != null)) {
            ToolTip1.Show(ht.SubItem.Tag, sender, ht.SubItem.Bounds.Location, 2000);
        }
    }
    
}

Open in new window

0
 
rishaanAuthor Commented:
How to define Tooltip

       ToolTip1.Show(ht.SubItem.Tag, sender, ht.SubItem.Bounds.Location, 2000);
     
0
 
Wayne Taylor (webtubbs)AstronautCommented:
Add a tooltip control to your form.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
rishaanAuthor Commented:
Error      5      The best overloaded method match for 'System.Windows.Forms.ToolTip.Show(string, System.Windows.Forms.IWin32Window, System.Drawing.Point, int)' has some invalid arguments

Error      6      Argument '2': cannot convert from 'object' to 'System.Windows.Forms.IWin32Window'
0
 
Wayne Taylor (webtubbs)AstronautCommented:
Either turn Option Strict Off, or convert "sender" to a ListView (which it is). The best way to find out the appropriate object types for methods is to use the F1 key.
ToolTip1.Show(ht.SubItem.Tag, (ListView)sender, ht.SubItem.Bounds.Location, 2000);

Open in new window

0
 
rishaanAuthor Commented:
It works ...Thanks a lot.....Is it possible to display this tooltip on headercell.
0
 
Wayne Taylor (webtubbs)AstronautCommented:
You mean when the mouse is over a column header? No, unfortunately there's not.
0
 
rishaanAuthor Commented:
Yes
0
 
arun_sabatCommented:
But the tooltip is diplaying over the subitem text itself.It should diplay slightly down to the subitem text.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now