Jump to content

unable to get index from clicked listview


gcue
 Share

Recommended Posts

hello

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

$iWindowStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS)
$iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
$iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)

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)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Populate_Common_Issues()

GUISetState()

While 1
    Sleep(10)
WEnd

Func Populate_Common_Issues()

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

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)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

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

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

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

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

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

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

EndFunc   ;==>Debug

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

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

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...