Jump to content

unable to get index from clicked listview

Recommended Posts



i am trying to get the index for the left clicked listview item.  i am using wm_notify and cant figure out why it's not working - any help is GREATLY appreciated!

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <GUIComboBox.au3>
#include <ComboConstants.au3>
#include <GuiListview.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $script_name = "Products", $script_exe = $script_name & ".exe"
Global $msg_normal = 262144, $msg_prompt = 262148, $msg_retry = 262150, $msg_error = 262160


GUICreate($script_name, 505, 620)

GUICtrlCreateLabel("Products", 20, 140, 150, 20)
$listview = GUICtrlCreateListView("Product|Description", 20, 160, 460, 300, $iWindowStyle, $iExWindowStyle)

GUICtrlCreateLabel("&Description:", 20, 470, 100, 20)
$description_input = GUICtrlCreateEdit("", 20, 490, 460, 80, $ES_MULTILINE)

_GUICtrlListView_SetExtendedListViewStyle($listview, $iExListViewStyle)
_GUICtrlListView_SetColumnWidth($listview, 0, 70)
_GUICtrlListView_SetColumnWidth($listview, 1, 255)


GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")



While 1

Func Populate_Common_Issues()

    For $x = 0 To 5
        GUICtrlCreateListViewItem($x & "|" & $x + 1 & "|" & $x + 2, $listview)

EndFunc   ;==>Populate_Common_Issues

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $listview
    If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    $index = DllStructGetData($tInfo, "Index")

                    $product = _GUICtrlListView_GetItemText($listview, $index, 0)
                    $description = _GUICtrlListView_GetItemText($listview, $index, 1)
                    Debug($index, $product, $description)
;~                  Product_Set_Type($product)

;~                  GUICtrlSetData($products_combo, "")
;~                  GUICtrlSetData($products_combo, $Products_SQL, $product)

;~                  GUICtrlSetData($description_input, $description)


EndFunc   ;==>WM_NOTIFY

Func Debug($variable1 = "", $variable2 = "", $variable3 = "", $variable4 = "")

;~  #include <array.au3>
;~  $msg_normal = 0

    If IsArray($variable1) Then
        If $variable2 <> "" Then
            $variable1 &= @CRLF & $variable2

        If $variable3 <> "" Then
            $variable1 &= @CRLF & $variable3

        If $variable4 <> "" Then
            $variable1 &= @CRLF & $variable4

        MsgBox($msg_normal, "Debug", $variable1)

EndFunc   ;==>Debug

Func _Exit()
EndFunc   ;==>_Exit


Share this post

Link to post
Share on other sites

Sorry there was originally 3 columns. But issue still is apparent?  When I click any of the list view items. Wm_notify says it's index 0 no matter which item I click

Share this post

Link to post
Share on other sites

Works for me when you correct this line.

GUICtrlCreateListViewItem($x & "|" & $x + 1 , $listview)

Your script won't even display anything so I'm not sure you're testing this before you post it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites

I am using anow older version 3.3.12 which may be why?   Not sure why you aren't seeing anything displayed. Works for me. I'll try again when I get home. Thanks

Share this post

Link to post
Share on other sites

i corrected the line and it's still not working... strange - like i mentioned using 3.3.12.. ill try upgrading


Share this post

Link to post
Share on other sites

yep that was it.. the PC actually had - yikes!

my apologies

thanks for your help/validation

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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.