Sign in to follow this  
Followers 0
ca143508

GuiCtrlListView

3 posts in this topic

HeyGuys,

I have a simple listview with 3 columns and some data in it. How can I have a message box popup with text from column 3 for example after I have clicked on an item in that list?

Any help would be great.

Cheers.

Mike

Share this post


Link to post
Share on other sites



Look up these functions, I'm pretty sure you can then put 2 and 2 together.

_GuiCtrlListView_GetSelectedIndices()

_GuiCtrlListView_GetItemTextString()

Share this post


Link to post
Share on other sites

ca143508

Try this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$hGUI = GUICreate("Test", 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems|", 10, 10, 280, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 2)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")
                    Local $iSubItem = DllStructGetData($tInfo, "SubItem")
                    
                    If $iSubItem = 2 Then
                        Local $iText = _GUICtrlListView_GetItemText($hListView, $iItem, $iSubItem)
                        MsgBox(0, "Message", $iText)
                    EndIf
            EndSwitch       
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

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  
Followers 0