rootx

listview color selected item [SOLVED]

26 posts in this topic

#1 ·  Posted (edited)

How can I change dynamically the background colors of the selected Item? THX

I try with...

#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Global $hListView

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 615, 437, 192, 124)
 GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF) ; will change background color

     $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)

                        _GUICtrlListView_SetBkColor($idListview, 0xff0000)
                        _GUICtrlListView_SetTextBkColor($idListview, 0xff0000)
                        _GUICtrlListView_SetTextColor($idListview, 0x0000FF00)

     $idButton = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
     $idItem1 = GUICtrlCreateListViewItem("item1|col22|col23", $idListview)
     $idItem2 = GUICtrlCreateListViewItem("item2|col12|col13", $idListview)
     $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
     $idItem4 = GUICtrlCreateListViewItem("item4|col32|col33", $idListview)
     $idItem5 = GUICtrlCreateListViewItem("item5|col32|col33", $idListview)
     $idItem9 = GUICtrlCreateListViewItem("item6|col32|col33", $idListview)
        GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop


        EndSwitch
    WEnd


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $idListview
    If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview)

    $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 ; The user has clicked the left mouse button within the control
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)

                    $Index = DllStructGetData($tInfo, "Index")
                    $ctrlID = _GUICtrlListView_GetItemParam($idListview,$Index)

                        Local $iItemText = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"), 0)
                        ConsoleWrite($iItemText&@CRLF)

                        _GUICtrlListView_SetTextBkColor($idListview, 0x2E8B57)

                        ;If BitAND(GUICtrlRead($idListview), $GUI_CHECKED) Then
                        ;   GUICtrlSetBkColor($ctrlID, 0xff0000)
                        ;Else
                        ;    GUICtrlSetBkColor($ctrlID, 0xffff00)
                        ;EndIf



            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIF

 

Edited by rootx

Share this post


Link to post
Share on other sites



I'm not sure what you're asking? Do you want to change the color of the currently highlighted item when you click it? Or do you want it to change when you press the button?

When I click an item in your code it changes the background color of that item, so aren't you already doing what you need?

Share this post


Link to post
Share on other sites

rrotx,

Take a look at my GUIListViewEx UDF (the link is in my sig) as that allows you to colour all the ListView items if required. Run Example 6: Use the "Save" and "Load" buttons to populate the RH ListView and then you can change the background colour of the selected item between blue and orange (obviously you could choose other colours if required).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites
1 hour ago, Melba23 said:

rrotx,

Take a look at my GUIListViewEx UDF (the link is in my sig) as that allows you to colour all the ListView items if required. Run Example 6: Use the "Save" and "Load" buttons to populate the RH ListView and then you can change the background colour of the selected item between blue and orange (obviously you could choose other colours if required).

M23

Thx, I tried example 6... but I'm not sure again,

#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"


#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 615, 437, 192, 124)
 GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF) ; will change background color

     $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
    ; Set required colours for ListView elements - change = pink field
    Local $aSelCol[4] = [Default, "0xFFCCCC", Default, Default] ;<--------------------------------------------
    _GUIListViewEx_SetDefColours($idListview, $aSelCol)


     $idButton = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
     $idItem1 = GUICtrlCreateListViewItem("item1|col22|col23", $idListview)
     $idItem2 = GUICtrlCreateListViewItem("item2|col12|col13", $idListview)
     $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
     $idItem4 = GUICtrlCreateListViewItem("item4|col32|col33", $idListview)
     $idItem5 = GUICtrlCreateListViewItem("item5|col32|col33", $idListview)
     $idItem9 = GUICtrlCreateListViewItem("item6|col32|col33", $idListview)
     _GUIListViewEx_MsgRegister()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idButton
            Local $aSelCol[4] = ["", "", "0x000000", "0xFF8000"] ;<--------------------------------------------
            _GUIListViewEx_SetDefColours($idListview, $aSelCol)



        EndSwitch
    WEnd


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $idListview
    If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview)

    $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 ; The user has clicked the left mouse button within the control
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)

                    $Index = DllStructGetData($tInfo, "Index")
                    $ctrlID = _GUICtrlListView_GetItemParam($idListview,$Index)

                        Local $iItemText = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"), 0)
                        ConsoleWrite($iItemText&@CRLF)

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIF

 

Share this post


Link to post
Share on other sites

rootx,

If you cannot be bothered to read about the UDF and correctly integrate it into your script, then it is hardly surprising that it does not work. I will see what I can do this evening.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

rootx,

Try this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include "GUIListViewEx.au3"

$Form1 = GUICreate("Form1", 615, 437, 192, 124)

$idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
_GUICtrlListView_SetExtendedListViewStyle($idListview, $LVS_EX_FULLROWSELECT)

$idButton = GUICtrlCreateButton("Value?", 75, 170, 70, 20)

$idItem1 = GUICtrlCreateListViewItem("item1|col22|col23", $idListview)
$idItem2 = GUICtrlCreateListViewItem("item2|col12|col13", $idListview)
$idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
$idItem4 = GUICtrlCreateListViewItem("item4|col32|col33", $idListview)
$idItem5 = GUICtrlCreateListViewItem("item5|col32|col33", $idListview)
$idItem9 = GUICtrlCreateListViewItem("item6|col32|col33", $idListview)

$aLVArray = _GUIListViewEx_ReadToArray($idListview)

$iLV_Index = _GUIListViewEx_Init($idListview, $aLVArray, 0, 0, True, 32 + 512)

; Set required colours for ListView elements - change = pink field when selected
Local $aSelCol[4] = [Default, Default, Default, "0xFFCCCC"]
_GUIListViewEx_SetDefColours($iLV_Index, $aSelCol)

_GUIListViewEx_MsgRegister(False)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

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

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

        Local $hLV = DllStructGetData($tStruct, 1)
        Local $iItem = DllStructGetData($tStruct, 4)
        Local $iSubItem = DllStructGetData($tStruct, 5)
        Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)

        If $iCode = $NM_CLICK Then
            $sText = _GUICtrlListView_GetItemText($hLV, $iItem, $iSubItem)
            ConsoleWrite($sText & @CRLF)
        EndIf
    EndIf

    $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

    Return $iRet

EndFunc

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

Melba, I read the word file, and the script 6, I have extracted the function I was thinking of using in my purpose, I have not much experience with listview mea culpa. Thx

Share this post


Link to post
Share on other sites

rootx,

No problem, it is a complex UDF to understand - it took even me a couple of goes to get it working!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <StaticConstants.au3>
#include <GuiImageList.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <Date.au3>
#include <IE.au3>
#include "GUIListViewEx.au3"

HotKeySet("{ESC}", "On_Exit")

Global $bChanged

DirCreate(@DesktopDir&"\img")
DirCreate(@DesktopDir&"\ico")

;Graphics
Global $icod = @ScriptDir & "\img\defico.jpg"
Global $bg = @ScriptDir & "\img\def.jpg"
Global $ini = @ScriptDir & "\ini.ini"

For $z = 1 to 4
    IniWriteSection($ini,@ScriptDir&"\data\"&$z,"")
Next

$sect = IniReadSectionNames($ini)

For $s = 1 To UBound($sect) - 1
    IniWrite($ini,$sect[$s],"name",$s)
    IniWrite($ini,$sect[$s],"img",@ScriptDir&"\img\"&$s&".jpg")
    IniWrite($ini,$sect[$s],"icon",@ScriptDir&"\ico\"&$s&".ico")
    IniWrite($ini,$sect[$s],"background",@ScriptDir&"\img\"&$s&".jpg")
Next

$GUIH="600"
$GUIW="1024"
$LsX="172"
$LsY="33"
$LsW="340"
$LsH="481"

$Xcolor = "0x0000FFFF"
$Xfcolor = "0x0000FFFF"

_GDIPlus_Startup()

$Form1 = GUICreate("My LIB", 1024, 600, -1, -1)
GUICtrlSetDefColor($Xfcolor)
GUICtrlSetDefBkColor($Xcolor)

$Pic2 = GUICtrlCreatePic($bg, 820, 10, 200, 200, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN, $WS_BORDER))
;Create listview
$hListView = _GUICtrlListView_Create($Form1, "", 0, 0, 320, 600)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
; block resizing of columns
ControlDisable($Form1, "", HWnd(_GUICtrlListView_GetHeader($hListView)))

_GUICtrlListView_SetBkColor($hListView, $Xcolor)
_GUICtrlListView_SetTextBkColor($hListView, $Xcolor)
_GUICtrlListView_SetTextColor($hListView, 0x0000000)

;Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "", 320)
_GUICtrlListView_InsertColumn($hListView, 1, "Path", 0)

_GUIListViewEx_MsgRegister(False) ;<---------------------------------------

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')

GUISetState(@SW_SHOW)

;Slide Effect
Global $hGfx = _GDIPlus_GraphicsCreateFromHWND($Form1)
;clip control elements
Global $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $guiw, $guih)
Global $hChild = _WinAPI_GetWindow($Form1, $GW_CHILD)
Global $aRect
Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, $aRect[0], $aRect[1], $aRect[2], $aRect[3], 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGfx, $hRegion)
_GDIPlus_RegionDispose($hRegion)
Global $hBmp1 = _GDIPlus_ImageLoadFromFile($bg)
_GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp1, 0, 0, $guiw, $guih)

read()

_GUICtrlListView_RegisterSortCallBack($hListView)

While 1
    If $bChanged Then
        Local $n = 1, $guihx = $guih + 50
        $itemc = _GUICtrlListView_GetSelectedIndices($hListView,false)
        Local $iItemTextd = _GUICtrlListView_GetItemText($hListView, $itemc, 1)
        $background = IniRead($ini, $iItemTextd, "background", "")
        If FileExists($background) Then
            Local $hBmp3 = _GDIPlus_ImageLoadFromFile(IniRead($ini, $iItemTextd, "background", ""))
            For $x = -$guiw To 0 Step 50
                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp3, 0, $x, $guiw, $guihx)
            Next
            _GDIPlus_ImageDispose($hBmp3)
        Else
            Local $hBmp3 = _GDIPlus_ImageLoadFromFile($bg)
            For $x = -$guiw To 0 Step 50
                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp3, 0, $x, $guiw, $guihx)
            Next
            _GDIPlus_ImageDispose($hBmp3)
        EndIf
        $pics = IniRead($ini, $iItemTextd, "img", "")
            If FileExists($pics) Then
                GUICtrlSetImage($Pic2, $pics)
            Else
                GUICtrlSetImage($Pic2, $icod)
            EndIf
        $bChanged = False
    EndIf

    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $Form1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    _GDIPlus_ImageDispose($hBmp1)
                    _GDIPlus_GraphicsDispose($hGfx)
                    _GDIPlus_Shutdown()
            EndSwitch
    EndSwitch
WEnd

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

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $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 ; The user has clicked the left mouse button within the control
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    If DllStructGetData($tInfo, "Index") = -1 Then
                        ;ConsoleWrite("no item" & @CRLF)
                    Else

                        Local $iItemText = _GUICtrlListView_GetItemText($hListView, DllStructGetData($tInfo, "Index"), 1)
                        $pics = IniRead($ini, $iItemText, "img", "")
                        If FileExists($pics) Then
                            GUICtrlSetImage($Pic2, $pics)
                        Else
                            GUICtrlSetImage($Pic2, $icod)
                        EndIf
                        $item = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $Index), '|')
                        $itemx = $item[1]
                        $item2 = IniRead($ini, $iItemText, "background", "")
                        Local $n = 1, $guihx = $guih + 50
                        If FileExists($item2) Then
                            Local $hBmp2 = _GDIPlus_ImageLoadFromFile(IniRead($ini, $iItemText, "background", ""))
                            For $x = -$guiw To 0 Step 50
                                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx)
                            Next
                            _GDIPlus_ImageDispose($hBmp2)
                        Else
                            Local $hBmp2 = _GDIPlus_ImageLoadFromFile($bg)
                            For $x = -$guiw To 0 Step 50
                                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx)
                            Next
                            _GDIPlus_ImageDispose($hBmp2)
                        EndIf
                    EndIf

                Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
                    $iKey = DllStructGetData($tInfo, "VKey")
                    Switch $iKey
                        Case 38, 40
                            $bChanged = True
                    EndSwitch
            EndSwitch
    EndSwitch

            $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam);<---------------------------------------
            Return $iRet;<---------------------------------------

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Func read()
    Local $tot = 0
    If FileExists($ini) Then
        $hImage = _GUIImageList_Create(48, 48, 5, 1)
        _GDIPlus_Startup()
        $aArrays = IniReadSectionNames($ini)
        _ArrayColInsert($aArrays, 1)
        For $s = 1 To UBound($aArrays) - 1
            $aArrays[$s][1] = StringRegExp($aArrays[$s][0], '.*\\(.*)\\', 1)[0]
        Next
        _ArrayColDelete($aArrays, 1, True)
        If Not @error Then
            For $i = 1 To UBound($aArrays) - 1
                $n = IniRead($ini, $aArrays[$i], "name", "")
                $z = IniRead($ini, $aArrays[$i], "icon", "")
                ;load icon and upscale the icon to 48x48 pixels
                $hBitmap = _GDIPlus_BitmapCreateFromFile($z)
                $hBitmap_scaled = _GDIPlus_ImageResize($hBitmap, 48, 48)
                $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled)
                _GDIPlus_BitmapDispose($hBitmap_scaled)
                _GDIPlus_BitmapDispose($hBitmap)
                $ico = _GUIImageList_Add($hImage, $hBitmap_GDI)
                _GUICtrlListView_SetImageList($hListView, $hImage, 1)
                _GUICtrlListView_AddItem($hListView, $n, $ico)
                _GUICtrlListView_AddSubItem($hListView, $i - 1, $aArrays[$i], 1)
                $tot += 1
            Next

                $aLVArray = _GUIListViewEx_ReadToArray($hListView);<---------------------------------------
                $iLV_Index = _GUIListViewEx_Init($hListView, $aLVArray, 0, 0, True, 32 + 512);<---------------------------------------
                ; Set required colours for ListView elements - change = pink field when selected;<---------------------------------------
                Local $aSelCol[4] = [Default, Default, Default, "0xFFCCCC"];<---------------------------------------
                _GUIListViewEx_SetDefColours($iLV_Index, $aSelCol);<---------------------------------------


            _GDIPlus_Shutdown()
        EndIf
    EndIf
EndFunc   ;==>read

 

img.zip

Share this post


Link to post
Share on other sites

#10 ·  Posted

Hi,

For anyone wondering about the enigmatic code posted above, I received a PM stating:

Quote

when I try to use the keyboard .. UP DOWN arrow does not work, the images do not change anymore, it only works the click event

Now the code is in open forum I am looking at it.

A timely reminder that the Forum rules are quite clear about asking for help via PM - DO NOT DO IT!

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#11 ·  Posted

rootx,

Looking at the code I see that you are using images within the ListView. My UDF does not cater for this and so there is no way it can be integrated into your script.

This is yet another example of a thread where the original question does not explain the full extent of the requirement, leading to a lot of wasted time as possible solutions are proposed which subsequently turn out to be far from what is actually  required. It is always a good idea to explain what is needed in as much detail as possible when starting a thread - then those who offer help can at least be sure that they are not wasting their time.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#12 ·  Posted

1 hour ago, Melba23 said:

rootx,

Looking at the code I see that you are using images within the ListView. My UDF does not cater for this and so there is no way it can be integrated into your script.

This is yet another example of a thread where the original question does not explain the full extent of the requirement, leading to a lot of wasted time as possible solutions are proposed which subsequently turn out to be far from what is actually  required. It is always a good idea to explain what is needed in as much detail as possible when starting a thread - then those who offer help can at least be sure that they are not wasting their time.

M23

THX M23, your UDF works fine with the click event, and change the picture and color of the selected text line. My specific problem is when I use the keybinding $LVN_KEYDOWN.

So, I hope someone have one idea to solve or to show me where I must look in the Autoit Helpline Functions.

Thx you all

Share this post


Link to post
Share on other sites

#13 ·  Posted

rootx,

I am really surprised to hear that you get the UDF to work with that ListView. I have looked a the code and I cannot see a problem - I will look again this afternoon after my Spanish lesson.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#14 ·  Posted

11 minutes ago, Melba23 said:

rootx,

I am really surprised to hear that you get the UDF to work with that ListView. I have looked a the code and I cannot see a problem - I will look again this afternoon after my Spanish lesson.

M23

THX, I found this 4now https://msdn.microsoft.com/en-us/library/bb775483(v=vs.85).aspx

Share this post


Link to post
Share on other sites

#15 ·  Posted

rootx,

That is what the UDF uses to do the colouring.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Hi guys I tried with the udf melba and even without it I can only using the click event, someone could explain to me why when I use $ LVN_KEYDOWN the image is not updated? Thank you.

#include <Misc.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <StaticConstants.au3>
#include <GuiImageList.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <Date.au3>
#include <IE.au3>
#include "GUIListViewEx.au3"

HotKeySet("{ESC}", "On_Exit")

Global $bChanged

DirCreate(@DesktopDir&"\img")
DirCreate(@DesktopDir&"\ico")

;Graphics
Global $icod = @ScriptDir & "\img\defico.jpg"
Global $bg = @ScriptDir & "\img\def.jpg"
Global $ini = @ScriptDir & "\ini.ini"

For $z = 1 to 4
    IniWriteSection($ini,@ScriptDir&"\data\"&$z,"")
Next

$sect = IniReadSectionNames($ini)

For $s = 1 To UBound($sect) - 1
    IniWrite($ini,$sect[$s],"name",$s)
    IniWrite($ini,$sect[$s],"img",@ScriptDir&"\img\"&$s&".jpg")
    IniWrite($ini,$sect[$s],"icon",@ScriptDir&"\ico\"&$s&".ico")
    IniWrite($ini,$sect[$s],"background",@ScriptDir&"\img\"&$s&".jpg")
Next

$GUIH="600"
$GUIW="1024"
$LsX="172"
$LsY="33"
$LsW="340"
$LsH="481"

$Xcolor = "0x0000FFFF"
$Xfcolor = "0x0000FFFF"

_GDIPlus_Startup()

$Form1 = GUICreate("My LIB", 1024, 600, -1, -1)
GUICtrlSetDefColor($Xfcolor)
GUICtrlSetDefBkColor($Xcolor)

$Pic2 = GUICtrlCreatePic($bg, 820, 10, 200, 200, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN, $WS_BORDER))
;Create listview
$hListView = _GUICtrlListView_Create($Form1, "", 0, 0, 320, 600)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
; block resizing of columns
ControlDisable($Form1, "", HWnd(_GUICtrlListView_GetHeader($hListView)))

_GUICtrlListView_SetBkColor($hListView, $Xcolor)
_GUICtrlListView_SetTextBkColor($hListView, $Xcolor)
_GUICtrlListView_SetTextColor($hListView, 0x0000000)

;Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "", 320)
_GUICtrlListView_InsertColumn($hListView, 1, "Path", 0)

_GUIListViewEx_MsgRegister(False) ;<---------------------------------------

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')

GUISetState(@SW_SHOW)

;Slide Effect
Global $hGfx = _GDIPlus_GraphicsCreateFromHWND($Form1)
;clip control elements
Global $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $guiw, $guih)
Global $hChild = _WinAPI_GetWindow($Form1, $GW_CHILD)
Global $aRect
Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, $aRect[0], $aRect[1], $aRect[2], $aRect[3], 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGfx, $hRegion)
_GDIPlus_RegionDispose($hRegion)
Global $hBmp1 = _GDIPlus_ImageLoadFromFile($bg)
_GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp1, 0, 0, $guiw, $guih)

read()

_GUICtrlListView_RegisterSortCallBack($hListView)

While 1
    If $bChanged Then
        Local $n = 1, $guihx = $guih + 50
        $itemc = _GUICtrlListView_GetSelectedIndices($hListView,false)
        Local $iItemTextd = _GUICtrlListView_GetItemText($hListView, $itemc, 1)
        $background = IniRead($ini, $iItemTextd, "background", "")
        If FileExists($background) Then
            Local $hBmp3 = _GDIPlus_ImageLoadFromFile(IniRead($ini, $iItemTextd, "background", ""))
            For $x = -$guiw To 0 Step 50
                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp3, 0, $x, $guiw, $guihx)
            Next
            _GDIPlus_ImageDispose($hBmp3)
        Else
            Local $hBmp3 = _GDIPlus_ImageLoadFromFile($bg)
            For $x = -$guiw To 0 Step 50
                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp3, 0, $x, $guiw, $guihx)
            Next
            _GDIPlus_ImageDispose($hBmp3)
        EndIf
        $pics = IniRead($ini, $iItemTextd, "img", "")
            If FileExists($pics) Then
                GUICtrlSetImage($Pic2, $pics)
            Else
                GUICtrlSetImage($Pic2, $icod)
            EndIf
        $bChanged = False
    EndIf

    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $Form1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    _GDIPlus_ImageDispose($hBmp1)
                    _GDIPlus_GraphicsDispose($hGfx)
                    _GDIPlus_Shutdown()
            EndSwitch
    EndSwitch
WEnd

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

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $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 ; The user has clicked the left mouse button within the control
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    If DllStructGetData($tInfo, "Index") = -1 Then
                        ;ConsoleWrite("no item" & @CRLF)
                    Else

                        Local $iItemText = _GUICtrlListView_GetItemText($hListView, DllStructGetData($tInfo, "Index"), 1)
                        $pics = IniRead($ini, $iItemText, "img", "")
                        If FileExists($pics) Then
                            GUICtrlSetImage($Pic2, $pics)
                        Else
                            GUICtrlSetImage($Pic2, $icod)
                        EndIf
                        $item = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $Index), '|')
                        $itemx = $item[1]
                        $item2 = IniRead($ini, $iItemText, "background", "")
                        Local $n = 1, $guihx = $guih + 50
                        If FileExists($item2) Then
                            Local $hBmp2 = _GDIPlus_ImageLoadFromFile(IniRead($ini, $iItemText, "background", ""))
                            For $x = -$guiw To 0 Step 50
                                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx)
                            Next
                            _GDIPlus_ImageDispose($hBmp2)
                        Else
                            Local $hBmp2 = _GDIPlus_ImageLoadFromFile($bg)
                            For $x = -$guiw To 0 Step 50
                                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx)
                            Next
                            _GDIPlus_ImageDispose($hBmp2)
                        EndIf
                    EndIf

                Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
                    $iKey = DllStructGetData($tInfo, "VKey")
                    Switch $iKey
                        Case 38, 40
                            $bChanged = True
                    EndSwitch
            EndSwitch
    EndSwitch

            $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam);<---------------------------------------
            Return $iRet;<---------------------------------------

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Func read()
    Local $tot = 0
    If FileExists($ini) Then
        $hImage = _GUIImageList_Create(48, 48, 5, 1)
        _GDIPlus_Startup()
        $aArrays = IniReadSectionNames($ini)
        _ArrayColInsert($aArrays, 1)
        For $s = 1 To UBound($aArrays) - 1
            $aArrays[$s][1] = StringRegExp($aArrays[$s][0], '.*\\(.*)\\', 1)[0]
        Next
        _ArrayColDelete($aArrays, 1, True)
        If Not @error Then
            For $i = 1 To UBound($aArrays) - 1
                $n = IniRead($ini, $aArrays[$i], "name", "")
                $z = IniRead($ini, $aArrays[$i], "icon", "")
                ;load icon and upscale the icon to 48x48 pixels
                $hBitmap = _GDIPlus_BitmapCreateFromFile($z)
                $hBitmap_scaled = _GDIPlus_ImageResize($hBitmap, 48, 48)
                $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled)
                _GDIPlus_BitmapDispose($hBitmap_scaled)
                _GDIPlus_BitmapDispose($hBitmap)
                $ico = _GUIImageList_Add($hImage, $hBitmap_GDI)
                _GUICtrlListView_SetImageList($hListView, $hImage, 1)
                _GUICtrlListView_AddItem($hListView, $n, $ico)
                _GUICtrlListView_AddSubItem($hListView, $i - 1, $aArrays[$i], 1)
                $tot += 1
            Next

                $aLVArray = _GUIListViewEx_ReadToArray($hListView);<---------------------------------------
                $iLV_Index = _GUIListViewEx_Init($hListView, $aLVArray, 0, 0, True, 32 + 512);<---------------------------------------
                ; Set required colours for ListView elements - change = pink field when selected;<---------------------------------------
                Local $aSelCol[4] = [Default, Default, Default, "0xFFCCCC"];<---------------------------------------
                _GUIListViewEx_SetDefColours($iLV_Index, $aSelCol);<---------------------------------------


            _GDIPlus_Shutdown()
        EndIf
    EndIf
EndFunc   ;==>read

 

img.zip

Edited by rootx

Share this post


Link to post
Share on other sites

Hello.... Is there someone who would have patience to help me,I tried with the udf melba and even without it I can only using the click event, someone could explain to me why when I use $ LVN_KEYDOWN the image is not updated?

THX.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

rootx,

Does no-one ever do any debugging of their own scripts nowadays? A few simple ConsoleWrites give the answer:

The reason the keys do not work is that the $itemc = _GUICtrlListView_GetSelectedIndices($hListView, False) line is returning nothing. As a result, the $iItemTextd = _GUICtrlListView_GetItemText($hListView, $itemc, 1) line always returns the same image path.

You will have to add some code to track which item is being selected by the keys rather than relying on the  _GUICtrlListView_GetSelectedIndices command. This is perhaps because my UDF is dealing with the colouring rather then leaving it to Windows - but do not hold your breath for me to amend it so that the command does return the correct value.

M23

Edit: You are in luck - the UDF should be able to do what you want and a new function is being prepared.

Edited by Melba23
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites
58 minutes ago, Melba23 said:

rootx,

Does no-one ever do any debugging of their own scripts nowadays? A few simple ConsoleWrites give the answer:

The reason the keys do not work is that the $itemc = _GUICtrlListView_GetSelectedIndices($hListView, False) line is returning nothing. As a result, the $iItemTextd = _GUICtrlListView_GetItemText($hListView, $itemc, 1) line always returns the same image path.

You will have to add some code to track which item is being selected by the keys rather than relying on the  _GUICtrlListView_GetSelectedIndices command. This is perhaps because my UDF is dealing with the colouring rather then leaving it to Windows - but do not hold your breath for me to amend it so that the command does return the correct value.

M23

Edit: You are in luck - the UDF should be able to do what you want and a new function is being prepared.

THX

Share this post


Link to post
Share on other sites

rootx,

This is working for me. Add this function to the end of your script:

; #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 amend the $LVN_KEYDOWN handler like this:

Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
                    $iKey = DllStructGetData($tInfo, "VKey")
                    ; Get current selection
                    $aLastSel = StringSplit(_GUIListViewEx_GetLastSelectedItem(), "|")
                    Switch $iKey
                        Case 38
                            ; Move up unless at top
                            $iCurrItem = $aLastSel[2] - 1
                            If $iCurrItem < 0 Then
                                $iCurrItem = 0
                            EndIf
                            _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem)
                        Case 40
                            ; 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)
                    EndSwitch

And you can remove all the If $bChanged section from your idle loop as the handler clicking on the item sets of another pass through the handler as if you had used the mouse.

As I said, it works for me - does it for you?

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

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

  • Similar Content

    • Wingens
      By Wingens
      Hi,
       
      I am trying to create a list view wich shows the content of an ini file. There is a pulldown menu wich allows me to check a certain status in the ini file if the status is found it should read out the key and in every section the same key is located after that it should fill out the listview with all results found.
       
      $OVERZICHTGUI = GUICreate("RMA Overzicht", 1235, 742, -1, -1) GUICtrlCreateLabel("Ingelogd als: " & $NAAMMEDEWERKER, 8, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", 8, 16, 185, 89) GUICtrlCreateLabel("Status:", 32, 40, 37, 17) $STATUS = GUICtrlCreateCombo("", 32, 64, 140, 25,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlSetData($STATUS, "Aangevraagd|Verzonden|Afgehandeld", "") GUICtrlCreateGroup("", -99, -99, 1, 1) $View = GUICtrlCreateListView("RMANR|RMANRLEV|DEBITNR|KLANT|STATUS|MODEL|SERIENR|AANGEMELDDOOR|AANMELDDATUM|VERZENDDATUM|RETOURDATUM|KLACHT|OPLOSSING", 8, 120, 1218, 614) $Exit = GUICtrlCreateButton("Hoofdmenu", 1104, 8, 123, 33) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $EXIT $YesOrNo = msgBox(4,"","Terug naar het hoofdmenu?") If $YesOrNo = 6 then GUIDelete($OVERZICHTGUI) MAINMENU() ExitLoop EndIf Case $STATUS $GO = 1 $STATE = GUICtrlRead($STATUS) Local $aArray = IniReadSection(@ScriptDir & "\DB\rma.ini", "STATUS") _ArrayDisplay($aArray, "Gevonden") $FOUNDRMANR = _ArraySearch($aArray, $STATE) MsgBox(4096, "", $FOUNDRMANR) If $FOUNDRMANR = -1 Then MsgBox(4096, "Not Found", "No RMA requests with this status found.") $GO = 0 EndIf If $GO = 1 Then $VAR = IniRead(@ScriptDir & "\DB\rma.ini", "RMANR", $FOUNDRMANR, "Not found") MsgBox(4096, "", $VAR) EndIf EndSwitch WEnd  
      rma-forum.ini
    • Xibalba
      By Xibalba
      Hello again dear forum!
      I want to switch "only text" with "image plus text" in each cell, but can't figure it out.
      #include <GuiConstantsEx.au3> #include <ColorConstants.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) ; GUI Local $StatusBox_Width = 800 Local $StatusBox_Height = 400 Local $hMainGUI = GUICreate("Example", $StatusBox_Width, $StatusBox_Height) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton") ; GUI MESSAGE LOOP GUISetState(@SW_SHOW, $hMainGUI) ; LIST VIEW Local $iListView = GUICtrlCreateListView("", 15, 40, 530, 80) _GUICtrlListView_SetExtendedListViewStyle($iListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) ; Load images Local $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($iListView), 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($iListView), 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($iListView), 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($iListView, $hImage, 1) ; Add columns _GUICtrlListView_AddColumn($iListView, "Column 1", 80) _GUICtrlListView_AddColumn($iListView, "Column 2", 80) _GUICtrlListView_AddColumn($iListView, "Column 3", 80) _GUICtrlListView_AddColumn($iListView, "Column 4", 80) _GUICtrlListView_AddColumn($iListView, "Column 5", 80) ; Add items _GUICtrlListView_AddItem($iListView, "One") _GUICtrlListView_AddSubItem($iListView, 0, "", 1, 1) _GUICtrlListView_AddSubItem($iListView, 0, "", 2, 2) GUICtrlCreateListViewItem("1|2|3|4|5", $iListView) MsgBox($MB_SYSTEMMODAL, "Test", "Updating cells...") ; Update cells _GUICtrlListView_SetItem($iListView, "New text", 0, 1) ; OK _GUICtrlListView_SetItem($iListView, "One(1)", 0, 0, 88) ; Here I want to remove the image completely (only way to HIDE image is to put an index that doesn't exist? - 88 in this case) _GUICtrlListView_AddItem($iListView, "Three", 7) ; Here I want to create the text without any image (space) - how? _GUICtrlListView_SetItemImage($iListView, 1, 0, 1) ; OK _GUICtrlListView_SetItemImage($iListView, 0, 1, 2) ; OK While 1 Sleep(100) ; Sleep to reduce CPU usage WEnd Func CLOSEButton() ; Note: At this point @GUI_CtrlId would equal $GUI_EVENT_CLOSE, ; and @GUI_WinHandle would equal $hMainGUI ;MsgBox(0, "GUI Event", "You selected CLOSE! Exiting...") Exit EndFunc ;==>CLOSEButton Basically, see the comments in the code what I want to accomplish (when clicking OK):
      I want the red box to disappear completely (now bypassed by stating an image index that doesn't exist) I want to create the last row - "Three" - without any image whatsoever. The "OK" comments are the behavior I want to be able to use in certain cases. I'm also puzzled why the value "1" is originally indented while the value "2" is not?!
       
      If it matters, I'm running an older version of AutoIt (v3.3.10.2)
    • rootx
      By rootx
      Holà, I would like to understand why when I select a subitem remains the focus on it. THX
      ;Rootx #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <GuiImageList.au3> #include <MsgBoxConstants.au3> #include <GuiListView.au3> Global $idListview #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 450, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 16, 16, 75, 25) $idListview = GUICtrlCreateListView("", 16, 56, 586, 358, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_AUTOARRANGE), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES)) _GUICtrlListView_InsertColumn($idListview, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($idListview, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($idListview, 2, "Column 3", 100) _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1, 1) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2, 1) _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1, 1) _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 3", 2,1) _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2) _GUICtrlListView_AddSubItem($idListview, 2, "Row 3: Col 2",1, 1) _GUICtrlListView_AddSubItem($idListview, 2, "Row 3: Col 3",2, 1) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iCol = DllStructGetData($tInfo, "SubItem") ConsoleWrite("Column clicked: " & $iCol & @CRLF) Case $NM_CLICK $aHit = _GUICtrlListView_SubItemHitTest($hWndFrom) $LVEIP_Item = $aHit[0] $LVEIP_SubItem = $aHit[1] Local $tItem $tItem = DllStructCreate($tagLVITEM) DllStructSetData($tItem, "Mask", $LVIF_STATE) DllStructSetData($tItem, "Item", $LVEIP_Item) DllStructSetData($tItem, "SubItem", $LVEIP_SubItem) DllStructSetData($tItem, "State", $LVIS_SELECTED) DllStructSetData($tItem, "StateMask", $LVIS_SELECTED) _GUICtrlListView_SetItemEx($hWndFrom, $tItem) ConsoleWrite("Selected Cell " & _GUICtrlListView_GetItemText($idListview,$LVEIP_Item,$LVEIP_SubItem)&@CRLF) EndSwitch EndSwitch EndFunc  
    • david1337
      By david1337
      Hey guys
      This may be quite simple, but I haven't manage to solve it yet :/
      All I want to do is get the ID of Xitem, so I can click it with " _GUICtrlListView_ClickItem" .
      So I need to find the item based on the that fact that I know the text/string name of that item.
       
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Example() Func Example() GUICreate("listview items", 300, 300, -1, -1) Local $idListview = GUICtrlCreateListView("col1", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING) Local $idButton = GUICtrlCreateButton("ID_of_Xitem?", 75, 170, 70, 20) Local $idItem1 = GUICtrlCreateListViewItem("Aitem", $idListview) Local $idItem2 = GUICtrlCreateListViewItem("Xitem", $idListview) Local $idItem3 = GUICtrlCreateListViewItem("Zitem", $idListview) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox(0,"","ID of Xitem is ?") _GUICtrlListView_ClickItem($clv, ?) EndSwitch WEnd EndFunc ;==>Example  
    • skybax
      By skybax
      Good morning all,
      I have a question regarding a situation im in...
       
      I have an array with information from sql query, how can i send this information to a listview ?
       
      $citeste_daune = "SELECT `id_dauna`,`data_incident`,`sala`,`autor`,`suma` FROM `daune` WHERE `status`=1;" $sa_citit_daune = _query($sqlinstance, $citeste_daune) Global $aresult[10001][5] = [[10000, 5]] Global $iindex = 0 With $sa_citit_daune While NOT .eof $aresult[$iindex][0] = .fields("id_dauna").value $aresult[$iindex][1] = .fields("data_incident").value $aresult[$iindex][2] = .fields("sala").value $aresult[$iindex][3] = .fields("autor").value $aresult[$iindex][4] = .fields("suma").value $iindex = $iindex + 1 .movenext WEnd EndWith ReDim $aresult[$iindex][5] $aresult[0][0] = $iindex - 1 _ArrayDisplay($aresult) GUICtrlCreateListViewItem(_ArrayToString($aresult), $lista_daune_active)  
      This is what i see when i execure _ArrayDisplay($aresult)