Jump to content
Sign in to follow this  
PartyPooper

Tips for Listview items

Recommended Posts

PartyPooper

I'm trying to set tips for individual items in a listview, however, I'm not having much success. I was hoping that the individual tips would display as the cursor hovered over each item, but it doesn't seem to work (see code for example). Does anyone know if it's even possible to do?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $listview, $item1, $item2, $item3, $msg

    GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF)  ; will change background color

    $listview = GUICtrlCreateListView("col1|col2|col3", 10, 10, 200, 150,BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $WS_EX_CLIENTEDGE)
    _GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_TRACKSELECT, $LVS_EX_UNDERLINEHOT, $LVS_EX_DOUBLEBUFFER))
    $item1 = GUICtrlCreateListViewItem("item1|stuff|stuff", $listview)
    GUICtrlSetTip($item1,"item1")
    $item2 = GUICtrlCreateListViewItem("item2|stuff|stuff", $listview)
    GUICtrlSetTip($item2,"item2")
    $item3 = GUICtrlCreateListViewItem("item3|stuff|stuff", $listview)
    GUICtrlSetTip($item3,"item3")
    GUISetState()
    Do
        $msg = GUIGetMsg()

        Select
            Case $msg = $listview
                MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites
water

I searched the forum and found the following post.

Insert

#include <WindowsConstants.au3>
and it runs just fine.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
picaxe

; by picaxe
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

Global $hListView, $hStatus
Global $aToolTipText[16][3] = [["First tooltip", "", "Second tooltip"],["Third tooltip", "Fourth tooltip", ""], _
    ["", "", ""],["", "", ""],["", "", ""],["", "Fifth tooltip", ""],["", "", "Sixth tooltip"], _
    ["", "", ""],["", "", ""],["", "", ""],["", "Seventh tooltip", ""]]

Local $hGUI = GUICreate("ListView Hover Tooltips", 395, 320)
$hListView = GUICtrlCreateListView("", 5, 5, 385, 290)
$hListView = GUICtrlGetHandle($hListView)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_TRACKSELECT))
$hStatus = _GUICtrlStatusBar_Create($hGUI)
_GUICtrlStatusBar_SetSimple($hStatus, True)
GUISetState()

_GUICtrlListView_AddColumn($hListView, "Column 1", 100)
_GUICtrlListView_AddColumn($hListView, "Column 2", 100)
_GUICtrlListView_AddColumn($hListView, "Column 3", 100)

For $i = 0 To 15
    $j = "Row " & StringFormat("%.02u", $i)
    _GUICtrlListView_AddItem($hListView, $j & ": Col 1")
    _GUICtrlListView_AddSubItem($hListView, $i, $j & ": Col 2", 1)
    _GUICtrlListView_AddSubItem($hListView, $i, $j & ": Col 3", 2)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Do
    Sleep(20)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Exit

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $LVN_HOTTRACK
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    Local $iItem = DllStructGetData($tInfo, "Item"), $iSubItem = DllStructGetData($tInfo, "SubItem")
                    If Not ($iItem = -1 Or $iSubItem = -1) Then
                        _GUICtrlStatusBar_SetText($hStatus, "Item: " & $iItem & " SubItem: " & $iSubItem)
                        If $aToolTipText[$iItem][$iSubItem] <> "" Then
                            ToolTip($aToolTipText[$iItem][$iSubItem])
                        Else
                            ToolTip("")
                        EndIf
                    Else
                        _GUICtrlStatusBar_SetText($hStatus, "")
                        ToolTip("")
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Edit: correct spelling

Edited by picaxe

Share this post


Link to post
Share on other sites
PartyPooper

I searched the forum and found the following post.

Insert

#include <WindowsConstants.au3>
and it runs just fine.

Thanks water but it's not quite what I'm after (the tooltips in this case form part of the listview item text which is not what I want). It has given me something else to look at though :-)

Share this post


Link to post
Share on other sites
PartyPooper

...

Thanks picaxe, this is what I'm after although it's somewhat more complicated than I hoped but it has given me a start point. Cheers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×