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?
rishaanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rishaanAuthor Commented:
How to define Tooltip

       ToolTip1.Show(ht.SubItem.Tag, sender, ht.SubItem.Bounds.Location, 2000);
     
0
Wayne Taylor (webtubbs)Commented:
Add a tooltip control to your form.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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)Commented:
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)Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.