Jump to content

GuiCtrlListView


Recommended Posts

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

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...