How to set tooltip for a ListviewSubItem

眉间皱痕 提交于 2019-12-18 08:11:28

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/13069137/how-to-set-tooltip-for-a-listviewsubitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!