How to set tooltips on ListView Subitems in .Net

后端 未结 5 1383
轻奢々
轻奢々 2021-02-10 09:15

I am trying to set the tool tip text for some of my subitems in my listview control. I am unable to get the tool tip to show up.

Anyone have any suggestions?

         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-10 09:19

    ObjectListView (an open source wrapper around .NET WinForms ListView) has builtin support for cell tooltips (and, yes, it does work with VB). You listen for a CellToolTip event and you can do things like this (which is admittedly excessive):

    If you don't want to use ObjectListView, you need to subclass ListView, listen for WM_NOTIFY messages, and then within those, respond to TTN_GETDISPINFO notifications, in a manner similar to this:

    case TTN_GETDISPINFO:
        ListViewHitTestInfo info = this.HitTest(this.PointToClient(Cursor.Position));
        if (info.Item != null && info.SubItem != null) {
            // Call some method of your own to get the tooltip you want
            String tip = this.GetCellToolTip(info.Item, info.SubItem); 
            if (!String.IsNullOrEmpty(tip)) {
                NativeMethods.TOOLTIPTEXT ttt = (NativeMethods.TOOLTIPTEXT)m.GetLParam(typeof(NativeMethods.TOOLTIPTEXT));
                ttt.lpszText = tip;
                if (this.RightToLeft == RightToLeft.Yes)
                    ttt.uFlags |= 4;
                Marshal.StructureToPtr(ttt, m.LParam, false);
                return; // do not do normal processing
            }
        }
        break;
    

    Obviously, this is C#, not VB, but you get the idea.

提交回复
热议问题