bourny

GuilistviewEx Detect selected item in list view

4 posts in this topic

Hi,

 

I am using Melba23`s UDF for my list view controls.  I am having difficulty trying to work out how to detect the item on the list view under the selection.  So far I can edit the UDF itself to give me an output of the array if I left or right click but I cannot isolate the item that is actually selected.

Here is what I have edited in the UDF however I do not want to edit the udf itself as this is unwise and I would rather call Melba23`s functions to return the information I need.

 

Here is the UDF code I have been playing with but again this this not what I want to do editing the UDF.

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

    #forceref $hWnd, $iMsg, $wParam

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    ; Check if enabled ListView or header
    For $iLV_Index = 1 To $aGLVEx_Data[0][0]
        If $aGLVEx_Data[$iLV_Index][0] = DllStructGetData($tStruct, 1) Then
            ExitLoop
        EndIf
    Next
    If $iLV_Index > $aGLVEx_Data[0][0] Then Return ; Not enabled

    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode


       Case $NM_RCLICK



         ; Set values for active ListView
            $aGLVEx_Data[0][1] = $iLV_Index
            $hGLVEx_SrcHandle = $aGLVEx_Data[$iLV_Index][0]
            $cGLVEx_SrcID = $aGLVEx_Data[$iLV_Index][1]
            ; Get and store item index
            $aGLVEx_Data[0][4] = DllStructGetData($tStruct, 4)

            If IsArray($aGLVEx_Data[$iLV_Index][4]) Then
               ; Load array
               $aGLVEx_SrcArray = $aGLVEx_Data[$iLV_Index][2]
               ; Load current ListView sort state array
              ; Local $aLVSortState = $aGLVEx_Data[$iLV_Index][4]
               ; Sort column - get column from from struct
              ; _GUICtrlListView_SimpleSort($hGLVEx_SrcHandle, $aLVSortState, $iCol)
               ; Store new ListView sort state array
              ; $aGLVEx_Data[$iLV_Index][4] = $aLVSortState
               ; Reread listview items into array
               Local $iDim2 = UBound($aGLVEx_SrcArray, 2) - 1
               For $j = 1 To $aGLVEx_SrcArray[0][0]
                   For $k = 0 To $iDim2

                      $H = _GUICtrlListView_GetItemText($hGLVEx_SrcHandle, $j - 1, $k)
                       $aGLVEx_SrcArray[$j][$k] = $H
                      msgbox(0, "", $H)
                   Next


               Next

               ;_ArrayDisplay($aGLVEx_SrcArray)

               ; Store amended array
               $aGLVEx_Data[$iLV_Index][2] = $aGLVEx_SrcArray
               ; Delete array
               $aGLVEx_SrcArray = 0
           EndIf

         ; Create Local array for checkboxes (if no checkboxes makes no difference)
         ; Create Local array for checkboxes (if no checkboxes makes no difference)
         ConsoleWrite("An Item Was clicked with the left mouse button" & @crlf)



       Case $NM_CLICK
            ConsoleWrite("An Item Was clicked with the left mouse button" & @crlf)

 

Share this post


Link to post
Share on other sites



Thanks .... 

 

I found it also and managed to embed a function into Melba23`s UDP to pass through the indices to allow me to simply loop through the list view with a counter that displays the item once the counter matches the indices.

 

 

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

    #forceref $hWnd, $iMsg, $wParam

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    ; Check if enabled ListView or header
    For $iLV_Index = 1 To $aGLVEx_Data[0][0]
        If $aGLVEx_Data[$iLV_Index][0] = DllStructGetData($tStruct, 1) Then
            ExitLoop
        EndIf
    Next
    If $iLV_Index > $aGLVEx_Data[0][0] Then Return ; Not enabled

    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode


       Case $NM_RCLICK

         $iIndex = _GUICtrlListView_GetSelectedIndices($hListView_Right)
         ShowRightClickedItem($iIndex)

         ConsoleWrite("An Item Was clicked with the left mouse button" & @crlf)



       Case $NM_CLICK
            ConsoleWrite("An Item Was clicked with the left mouse button" & @crlf)

 

Share this post


Link to post
Share on other sites

From reading 'A Beginner’s Guide To Melba23’s GUIListViewEx UDF'

it seems not neccesary to edit the UDF

Here i'm trying an example:

 

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