How to set tooltip for a ListviewSubItem
Asked Answered
C

1

7

I have a ListView control in Details view as that (the view that shows the list as a grid)

    mListView.View = View.Details; 
    mListView.mLVSelectedObject.ShowItemToolTips = true;

    ListViewItem listViewItem = mListView.Items.Add(lValue.Name);
    listViewItem.ToolTipText = "AAAAAAAAAAAAAAAAA";

The issue is that the tooltip only shows up when the cursors is over the first listview's column but not for the rest o them. I want to know if there's anyway to make it appear "easly" ?

Chariot answered 25/10, 2012 at 12:58 Comment(2)
Are you trying to add a tooltip for the whole listview, or do you want a different tooltip for each item?Pusey
I want wnat one tooltip for each row. (The same tooltip for every subitem of a listviewitem).Chariot
C
8

After some research. I've solved the issue this way, but I'm still wondering if there is another way to do that avoiding EventHandlers;

    ToolTip     mTooltip;
    Point mLastPos = new Point(-1, -1);

    private void listview_MouseMove(object sender, MouseEventArgs e)
    {
        ListViewHitTestInfo info    =   mLV.HitTest(e.X, e.Y);

        if (mTooltip == null)
            mTooltip = new ToolTip();

        if (mLastPos != e.Location)
        {
            if (info.Item != null && info.SubItem != null)
            {
                mTooltip.ToolTipTitle = info.Item.Text;
                mTooltip.Show(info.SubItem.Text, info.Item.ListView, e.X, e.Y, 20000);
            }
            else
            {
                mTooltip.SetToolTip(mLV, string.Empty);
            }
        }

        mLastPos = e.Location;
    }
Chariot answered 25/10, 2012 at 14:38 Comment(2)
Why aren't you handling MouseHover instead of MouseMove ?, besides you have the "ShowItemToolTips" property, just set it to true and you're fine.Casemaker
@Casemaker : It is really hard to use this function on MouseHover. The first problem you do not have the coordinates, you need to handle many other events and there are also unexpected errors. When I have the code completed (and it will not be normal length) I will post it here.Chantell

© 2022 - 2024 — McMap. All rights reserved.