Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

c# - How to set tooltip for a ListviewSubItem

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" ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...