Jump to content

[SOLVED] GUIListViewEx.au3 $LVN_KEYDOWN Need Help


 Share

Recommended Posts

I can not understand why it does not work, Where am I wrong?

 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include "GUIListViewEx.au3"


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 620, 437, 192, 124)
$ListView = GUICtrlCreateListView("", 10, 64, 600, 302, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
;_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
GUICtrlSetFont($ListView, 12, Default, Default, "Arial")
_GUICtrlListView_AddColumn($ListView, "Title", 180)
_GUICtrlListView_AddColumn($ListView, "Region", 180)
_GUICtrlListView_AddColumn($ListView, "Path", 180)

    _GUICtrlListView_AddItem($ListView, "Row 1: Col 1", 0)
        _GUICtrlListView_AddSubItem($ListView, 0, "Row 1: Col 2", 1, 1)
        _GUICtrlListView_AddSubItem($ListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($ListView, "Row 2: Col 1", 1)
        _GUICtrlListView_AddSubItem($ListView, 1, "Row 2: Col 2", 1, 2)
        _GUICtrlListView_AddSubItem($ListView, 1, "Row 2: Col 3", 2, 2)
    _GUICtrlListView_AddItem($ListView, "Row 3: Col 1", 2)
        _GUICtrlListView_AddSubItem($ListView, 2, "Row 3: Col 2", 1, 2)
        _GUICtrlListView_AddSubItem($ListView, 2, "Row 3: Col 3", 2, 2)

_GUIListViewEx_MsgRegister(False)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW,$Form1)

#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


; ========================================================
; This thing is responcible for click events
; ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom

        Case $hWndListView
            Switch $iCode

                Case $LVN_KEYDOWN

                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
                    $iKey = DllStructGetData($tInfo, "VKey")
                    ; Get current selection
                    $aLastSel = StringSplit(_GUIListViewEx_GetLastSelectedItem(), "|")
                    _ArrayDisplay($aLastSel) ;<------------ crash???
                    Switch $iKey
                        Case 38
                            If _GUIListViewEx_GetLastSelectedItem() <> "" Then
                                ; Move up unless at top
                                $iCurrItem = $aLastSel[2] - 1
                                If $iCurrItem < 0 Then
                                    $iCurrItem = 0
                                EndIf
                                _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem, "top", False, 1, 2)
                                $target = _GUICtrlListView_GetItemText($ListView, $iCurrItem, 1)
                            Else
                                _GUICtrlListView_ClickItem($hWndFrom, 0, "top", False, 1, 2)
                            EndIf
                        Case 40
                            If _GUIListViewEx_GetLastSelectedItem() <> "" Then
                                ; Move down unless at bottom
                                $iCurrItem = $aLastSel[2] + 1
                                If $iCurrItem >= _GUICtrlListView_GetItemCount($hWndFrom) Then
                                    $iCurrItem = _GUICtrlListView_GetItemCount($hWndFrom) - 1
                                EndIf
                                _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem, "down", False, 1, 2)
                                $targetb = _GUICtrlListView_GetItemText($ListView, $iCurrItem, 1)
                            Else
                                _GUICtrlListView_ClickItem($hWndFrom, 0, "down", False, 1, 2)
                            EndIf
                    EndSwitch

            EndSwitch
    EndSwitch
    $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam)
    Return $iRet
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _GUIListViewEx_GetLastSelectedItem($iLV_Index = 0)
    ; Check valid index
    Switch $iLV_Index
        Case 1 To $aGLVEx_Data[0][0]
            ; Valid index
        Case Else
            ; Get active ListView
            $iLV_Index = _GUIListViewEx_GetActive()
            ; If no ListView active
            If $iLV_Index = 0 Then Return SetError(1, 0, "")
    EndSwitch

    ; Read last selected item
    Local $iRow = $aGLVEx_Data[$iLV_Index][20]
    Local $iCol = $aGLVEx_Data[$iLV_Index][21]
    ; Check selection has been made
    If $iRow = -1 Or $iCol = -1 Then Return SetError(2, 0, "")
    ; Return selection details
    Return $iLV_Index & "|" & $iRow & "|" & $iCol

EndFunc   ;==>_GUIListViewEx_GetLastSelectedItem

 

Edited by rootx
Link to comment
Share on other sites

Just out of curiosity why the Switch $iKey for "up" and "down" arrow keys, this is the default behavior for those keys.  Also what does "down" and "top" in your _GuiCtrlListView_ClickItem function do, I haven't seen these options before and couldn't find them in help.

 

Link to comment
Share on other sites

Thx... Forget _Arraydisplay, I can not understand how to read the list view fields when I use the up and down keys, Melba had helped me in the past, and his UDF is very useful, but I do not understand this function _GUIListViewEx_GetLastSelectedItem($iLV_Index = 0)...

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include "GUIListViewEx.au3"


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 620, 437, 192, 124)
$ListView = GUICtrlCreateListView("", 10, 64, 600, 302);, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
;_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
GUICtrlSetFont($ListView, 12, Default, Default, "Arial")
_GUICtrlListView_AddColumn($ListView, "Title", 180)
_GUICtrlListView_AddColumn($ListView, "Region", 180)
_GUICtrlListView_AddColumn($ListView, "Path", 180)

    _GUICtrlListView_AddItem($ListView, "Row 1: Col 1", 0)
        _GUICtrlListView_AddSubItem($ListView, 0, "Row 1: Col 2", 1, 1)
        _GUICtrlListView_AddSubItem($ListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($ListView, "Row 2: Col 1", 1)
        _GUICtrlListView_AddSubItem($ListView, 1, "Row 2: Col 2", 1, 2)
        _GUICtrlListView_AddSubItem($ListView, 1, "Row 2: Col 3", 2, 2)
    _GUICtrlListView_AddItem($ListView, "Row 3: Col 1", 2)
        _GUICtrlListView_AddSubItem($ListView, 2, "Row 3: Col 2", 1, 2)
        _GUICtrlListView_AddSubItem($ListView, 2, "Row 3: Col 3", 2, 2)

_GUIListViewEx_MsgRegister(False)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW,$Form1)

#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


; ========================================================
; This thing is responcible for click events
; ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom

        Case $hWndListView
            Switch $iCode


                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    If DllStructGetData($tInfo, "Index") = -1 Then
                        ;ConsoleWrite("no item" & @CRLF)
                    Else
                        Local $col1 = _GUICtrlListView_GetItemText($ListView, DllStructGetData($tInfo, "Index"), 0)
                        Local $col2 = _GUICtrlListView_GetItemText($ListView, DllStructGetData($tInfo, "Index"), 1)
                        Local $col3 = _GUICtrlListView_GetItemText($ListView, DllStructGetData($tInfo, "Index"), 2)
                        ConsoleWrite($col1&" "&$col2&" "&$col3&@CRLF)
                    EndIf


                Case $LVN_KEYDOWN

                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
                    $iKey = DllStructGetData($tInfo, "VKey")
                    ; Get current selection
                    $aLastSel = StringSplit(_GUIListViewEx_GetLastSelectedItem(), "|")
                    ConsoleWrite($aLastSel[0] & "  " & $aLastSel[1])
                    Switch $iKey
                        Case 38
                            If _GUIListViewEx_GetLastSelectedItem() <> "" Then
                                ; Move up unless at top
                                $iCurrItem = $aLastSel[2] - 1
                                If $iCurrItem < 0 Then
                                    $iCurrItem = 0
                                EndIf
                                _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem, "top", False, 1, 2)
                                $target = _GUICtrlListView_GetItemText($ListView, $iCurrItem, 1)
                            Else
                                _GUICtrlListView_ClickItem($hWndFrom, 0, "top", False, 1, 2)
                            EndIf
                        Case 40
                            If _GUIListViewEx_GetLastSelectedItem() <> "" Then
                                ; Move down unless at bottom
                                $iCurrItem = $aLastSel[2] + 1
                                If $iCurrItem >= _GUICtrlListView_GetItemCount($hWndFrom) Then
                                    $iCurrItem = _GUICtrlListView_GetItemCount($hWndFrom) - 1
                                EndIf
                                _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem, "down", False, 1, 2)
                                $targetb = _GUICtrlListView_GetItemText($ListView, $iCurrItem, 1)
                            Else
                                _GUICtrlListView_ClickItem($hWndFrom, 0, "down", False, 1, 2)
                            EndIf
                    EndSwitch

            EndSwitch
    EndSwitch
    $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam)
    Return $iRet
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _GUIListViewEx_GetLastSelectedItem($iLV_Index = 0)
    ; Check valid index
    Switch $iLV_Index
        Case 1 To $aGLVEx_Data[0][0]
            ; Valid index
        Case Else
            ; Get active ListView
            $iLV_Index = _GUIListViewEx_GetActive()
            ; If no ListView active
            If $iLV_Index = 0 Then Return SetError(1, 0, "")
    EndSwitch

    ; Read last selected item
    Local $iRow = $aGLVEx_Data[$iLV_Index][20]
    Local $iCol = $aGLVEx_Data[$iLV_Index][21]
    ; Check selection has been made
    If $iRow = -1 Or $iCol = -1 Then Return SetError(2, 0, "")
    ; Return selection details
    Return $iLV_Index & "|" & $iRow & "|" & $iCol

EndFunc   ;==>_GUIListViewEx_GetLastSelectedItem

 

Link to comment
Share on other sites

43 minutes ago, Subz said:

Just out of curiosity why the Switch $iKey for "up" and "down" arrow keys, this is the default behavior for those keys.  Also what does "down" and "top" in your _GuiCtrlListView_ClickItem function do, I haven't seen these options before and couldn't find them in help.

 

; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_GetLastSelectedItem
; Description ...: Get last selected item in active or specified ListView
; Syntax.........: _GUIListViewEx_GetLastSelectedItem($iLV_Index = 0)
; Parameters ....: $iLV_Index - Index of ListView as returned by _GUIListViewEx_Init
; Requirement(s).: v3.3.10 +
; Return values .: Success: Delimited string ListViewIndex|Row|Col
;                  Failure: Returns "" and sets @error as follows:
;                      1 = No ListView yet active or invalid index passed
;                      2 = No item selected in
; Author ........: Melba23
; Modified ......:
; Remarks .......: If multiple items are selected, only the last selected is returned
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_GetLastSelectedItem($iLV_Index = 0)

    ; Check valid index
    Switch $iLV_Index
        Case 1 To $aGLVEx_Data[0][0]
            ; Valid index
        Case Else
            ; Get active ListView
            $iLV_Index = _GUIListViewEx_GetActive()
            ; If no ListView active
            If $iLV_Index = 0 Then Return SetError(1, 0, "")
    EndSwitch

    ; Read last selected item
    Local $iRow = $aGLVEx_Data[$iLV_Index][20]
    Local $iCol = $aGLVEx_Data[$iLV_Index][21]
    ; Check selection has been made
    If $iRow = -1 Or $iCol = -1 Then Return SetError(2, 0, "")
    ; Return selection details
    Return $iLV_Index & "|" & $iRow & "|" & $iCol

EndFunc

Now I try to solve it alone

Link to comment
Share on other sites

Not sure if this helps:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include "GUIListViewEx.au3"

Global $bLVN_KEYDOWN = False
$Form1 = GUICreate("Form1", 620, 437, 192, 124)
$ListView = GUICtrlCreateListView("", 10, 64, 600, 302)
GUICtrlSetFont($ListView, 12, Default, Default, "Arial")
_GUICtrlListView_AddColumn($ListView, "Title", 180)
_GUICtrlListView_AddColumn($ListView, "Region", 180)
_GUICtrlListView_AddColumn($ListView, "Path", 180)

    _GUICtrlListView_AddItem($ListView, "Row 1: Col 1", 0)
        _GUICtrlListView_AddSubItem($ListView, 0, "Row 1: Col 2", 1, 1)
        _GUICtrlListView_AddSubItem($ListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($ListView, "Row 2: Col 1", 1)
        _GUICtrlListView_AddSubItem($ListView, 1, "Row 2: Col 2", 1, 2)
        _GUICtrlListView_AddSubItem($ListView, 1, "Row 2: Col 3", 2, 2)
    _GUICtrlListView_AddItem($ListView, "Row 3: Col 1", 2)
        _GUICtrlListView_AddSubItem($ListView, 2, "Row 3: Col 2", 1, 2)
        _GUICtrlListView_AddSubItem($ListView, 2, "Row 3: Col 3", 2, 2)

Local $idTitle = GUICtrlCreateInput("Title", 10, 375, 150, 21)
Local $idRegion = GUICtrlCreateInput("Region", 10 + 155, 375, 150, 21)
Local $idPath = GUICtrlCreateInput("Path", 10 + 155 + 155, 375, 150, 21)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If $bLVN_KEYDOWN Then
        GUICtrlSetData($idTitle, _GUICtrlListView_GetItemText($ListView, _GUICtrlListView_GetSelectionMark($ListView), 0))
        GUICtrlSetData($idRegion, _GUICtrlListView_GetItemText($ListView, _GUICtrlListView_GetSelectionMark($ListView), 1))
        GUICtrlSetData($idPath, _GUICtrlListView_GetItemText($ListView, _GUICtrlListView_GetSelectionMark($ListView), 2))
        $bLVN_KEYDOWN = False
    EndIf
WEnd

; ========================================================
; This thing is responcible for click events
; ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    If DllStructGetData($tInfo, "Index") = -1 Then
                    Else
                        Local $col1 = _GUICtrlListView_GetItemText($ListView, DllStructGetData($tInfo, "Index"), 0)
                        Local $col2 = _GUICtrlListView_GetItemText($ListView, DllStructGetData($tInfo, "Index"), 1)
                        Local $col3 = _GUICtrlListView_GetItemText($ListView, DllStructGetData($tInfo, "Index"), 2)
                        ConsoleWrite($col1&" "&$col2&" "&$col3&@CRLF)
                    EndIf
                Case $LVN_KEYDOWN
                    $bLVN_KEYDOWN = True
            EndSwitch
    EndSwitch
    $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam)
    Return $iRet
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Link to comment
Share on other sites

!!!! $aLVArray = _GUIListViewEx_ReadToArray($ListView) and $iLV_Index = _GUIListViewEx_Init

I I forgot to use these .... Melba says in his help of the scritp .... mea culpa

 

Now work again!!!

Edited by rootx
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...