Jump to content
Sign in to follow this  
MikahS

ListView sorting using sort callback and $LVN_COLUMNCLICK

Recommended Posts

MikahS

Hello all,

Back again it seems. I've hit a snag in the below script. I use this on win 7 and XP machines frequently and have just realized that sorting using column headers is not 'working' (is not updating listview; it looks like something is going on behind the scenes..) when clicked. Also this does not show the sorting arrow when using the callback sort functionality.

So, to sum up, I am not seeing the arrow keys when clicking the column header to sort. And, it is not sorting the values in the $List1 ListView box on a win XP machine.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GUIEdit.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>

Local $List1, $List2, $List3, $List4, $GUIhandle
Local $Button19, $Button91, $ButtonAZ, $ButtonZA
Local $hChild_1, $cLabel_1, $cLabel_2, $cLabel_3


GUI()
Repaint()

Local $bSysMsg = False

Local $aRect = _GUICtrlListView_GetItemRect($List1, 0)
$iDeltaY = $aRect[3] - $aRect[1]

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)

_GUICtrlListView_RegisterSortCallBack($List1)
_GUICtrlListView_RegisterSortCallBack($List2)
_GUICtrlListView_RegisterSortCallBack($List3)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $GUIhandle
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    Quit()
            EndSwitch
            If $bSysMsg Then
                $bSysMsg = False
                _Resize_ListViews()
            EndIf
        Case $hChild_1
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hChild_1)
            EndSwitch
    EndSwitch
WEnd

Func Repaint()
    Local $L1, $L2, $L3
    _GUICtrlListView_BeginUpdate($List1)
    _GUICtrlListView_DeleteAllItems($List1)
    _GUICtrlListView_BeginUpdate($List2)
    _GUICtrlListView_DeleteAllItems($List2)
    _GUICtrlListView_BeginUpdate($List3)
    _GUICtrlListView_DeleteAllItems($List3)
    For $Index = 0 To 10 Step 1
        $L1 = _GUICtrlListView_AddItem($List1, $Index, $Index)
        $L2 = _GUICtrlListView_AddItem($List2, $Index, $Index)
        $L3 = _GUICtrlListView_AddItem($List3, $Index, $Index)
    Next
    _GUICtrlListView_SetColumnWidth($List1, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($List2, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_EndUpdate($List1)
    _GUICtrlListView_EndUpdate($List2)
    _GUICtrlListView_EndUpdate($List3)
EndFunc   ;==>Repaint

Func Quit()
    _GUICtrlListView_UnRegisterSortCallBack($List1)
    _GUICtrlListView_UnRegisterSortCallBack($List2)
    _GUICtrlListView_UnRegisterSortCallBack($List3)
    Exit
EndFunc   ;==>Quit

Func GUI()
    Local $Index, $LV1, $LV2, $LV3, $L1_EX, $L2_EX, $L3_EX
    $GUIhandle = GUICreate("ArchServer", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    $List1 = _GUICtrlListView_Create($GUIhandle, "Computer Name ", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ;;$ES_READONLY incase you don't want to be able to select text
    $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_1, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT)
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $List2 = _GUICtrlListView_Create($GUIhandle, "Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
    $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_2, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT)
    $List3 = _GUICtrlListView_Create($GUIhandle, "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
    $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_3, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $ActiveConnections = GUICtrlCreateList("0", 625, 486, 30, 30) ;dynamically updating list of connections as they come in
    GUICtrlSetResizing($ActiveConnections, $GUI_DOCKSIZE)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window
    For $Index = 0 To 10 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, _
            $ceLines, $cl
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Local Const $iLines = _SendMessage($List1, $LVM_GETTOPINDEX) - _SendMessage($List2, $LVM_GETTOPINDEX)
    _SendMessage($List2, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    _SendMessage($List3, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    Switch $hWndFrom
        Case $List1
            Switch $iCode
                Case $LVN_COLUMNCLICK
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List1)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List2
            Switch $iCode
                Case $LVN_COLUMNCLICK
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List2)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List3
            Switch $iCode
                Case $LVN_COLUMNCLICK
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List3)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
    _Resize_ListViews()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)
    Const $SC_MAXIMIZE = 0xF030
    Const $SC_RESTORE = 0xF120
    Switch $wParam
        Case $SC_MAXIMIZE, $SC_RESTORE
            $bSysMsg = True
    EndSwitch
EndFunc   ;==>_WM_SYSCOMMAND

Func _Resize_ListViews()
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_1)
    WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_2)
    WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_3)
    WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
EndFunc   ;==>_Resize_ListViews
;========RESIZE FUNCTIONALITY THANKS TO MELBA

All replies are much appreciated! :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
BrewManNH

This is one way to do it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GUIEdit.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>

Local $List1, $List2, $List3, $List4, $GUIhandle
Local $Button19, $Button91, $ButtonAZ, $ButtonZA
Local $hChild_1, $cLabel_1, $cLabel_2, $cLabel_3


GUI()
Repaint()

Local $bSysMsg = False

Local $aRect = _GUICtrlListView_GetItemRect($List1, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $List1 = ' & $List1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$iDeltaY = $aRect[3] - $aRect[1]

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)

_GUICtrlListView_RegisterSortCallBack($List1)
_GUICtrlListView_RegisterSortCallBack($List2)
_GUICtrlListView_RegisterSortCallBack($List3)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $GUIhandle
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $GUI_EVENT_CLOSE = ' & $GUI_EVENT_CLOSE & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                    Quit()
                Case $List1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $List2 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List2, GUICtrlGetState($List2))
                Case $List3 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List3, GUICtrlGetState($List3))
            EndSwitch
            If $bSysMsg Then
                $bSysMsg = False
                _Resize_ListViews()
            EndIf
        Case $hChild_1
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hChild_1)
            EndSwitch
    EndSwitch
WEnd

Func Repaint()
    Local $L1, $L2, $L3
    _GUICtrlListView_BeginUpdate($List1)
    _GUICtrlListView_DeleteAllItems($List1)
    _GUICtrlListView_BeginUpdate($List2)
    _GUICtrlListView_DeleteAllItems($List2)
    _GUICtrlListView_BeginUpdate($List3)
    _GUICtrlListView_DeleteAllItems($List3)
    For $Index = 0 To 10 Step 1
        $L1 = _GUICtrlListView_AddItem($List1, $Index, $Index)
        $L2 = _GUICtrlListView_AddItem($List2, $Index, $Index)
        $L3 = _GUICtrlListView_AddItem($List3, $Index, $Index)
    Next
    _GUICtrlListView_SetColumnWidth($List1, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($List2, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_EndUpdate($List1)
    _GUICtrlListView_EndUpdate($List2)
    _GUICtrlListView_EndUpdate($List3)
EndFunc   ;==>Repaint

Func Quit()
    _GUICtrlListView_UnRegisterSortCallBack($List1)
    _GUICtrlListView_UnRegisterSortCallBack($List2)
    _GUICtrlListView_UnRegisterSortCallBack($List3)
    Exit
EndFunc   ;==>Quit

Func GUI()
    Local $Index, $LV1, $LV2, $LV3, $L1_EX, $L2_EX, $L3_EX
    $GUIhandle = GUICreate("ArchServer", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    $List1 = GUICtrlCreateListView( "Computer Name ", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_1, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT)
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $List2 = GUICtrlCreateListView("Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_2, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT)
    $List3 = GUICtrlCreateListView( "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_3, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $ActiveConnections = GUICtrlCreateList("0", 625, 486, 30, 30) ;dynamically updating list of connections as they come in
    GUICtrlSetResizing($ActiveConnections, $GUI_DOCKSIZE)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window
    For $Index = 0 To 10 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, _
            $ceLines, $cl
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Local Const $iLines = _SendMessage($List1, $LVM_GETTOPINDEX) - _SendMessage($List2, $LVM_GETTOPINDEX)
    _SendMessage($List2, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    _SendMessage($List3, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    Switch $hWndFrom
        Case $List1
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List1)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List2
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List2)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List3
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List3)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
    _Resize_ListViews()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)
    Const $SC_MAXIMIZE = 0xF030
    Const $SC_RESTORE = 0xF120
    Switch $wParam
        Case $SC_MAXIMIZE, $SC_RESTORE
            $bSysMsg = True
    EndSwitch
EndFunc   ;==>_WM_SYSCOMMAND

Func _Resize_ListViews()
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_1)
    WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_2)
    WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_3)
    WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
EndFunc   ;==>_Resize_ListViews
;========RESIZE FUNCTIONALITY THANKS TO MELBA

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
MikahS

 

This is one way to do it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GUIEdit.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>

Local $List1, $List2, $List3, $List4, $GUIhandle
Local $Button19, $Button91, $ButtonAZ, $ButtonZA
Local $hChild_1, $cLabel_1, $cLabel_2, $cLabel_3


GUI()
Repaint()

Local $bSysMsg = False

Local $aRect = _GUICtrlListView_GetItemRect($List1, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $List1 = ' & $List1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$iDeltaY = $aRect[3] - $aRect[1]

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)

_GUICtrlListView_RegisterSortCallBack($List1)
_GUICtrlListView_RegisterSortCallBack($List2)
_GUICtrlListView_RegisterSortCallBack($List3)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $GUIhandle
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $GUI_EVENT_CLOSE = ' & $GUI_EVENT_CLOSE & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                    Quit()
                Case $List1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $List2 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List2, GUICtrlGetState($List2))
                Case $List3 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List3, GUICtrlGetState($List3))
            EndSwitch
            If $bSysMsg Then
                $bSysMsg = False
                _Resize_ListViews()
            EndIf
        Case $hChild_1
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hChild_1)
            EndSwitch
    EndSwitch
WEnd

Func Repaint()
    Local $L1, $L2, $L3
    _GUICtrlListView_BeginUpdate($List1)
    _GUICtrlListView_DeleteAllItems($List1)
    _GUICtrlListView_BeginUpdate($List2)
    _GUICtrlListView_DeleteAllItems($List2)
    _GUICtrlListView_BeginUpdate($List3)
    _GUICtrlListView_DeleteAllItems($List3)
    For $Index = 0 To 10 Step 1
        $L1 = _GUICtrlListView_AddItem($List1, $Index, $Index)
        $L2 = _GUICtrlListView_AddItem($List2, $Index, $Index)
        $L3 = _GUICtrlListView_AddItem($List3, $Index, $Index)
    Next
    _GUICtrlListView_SetColumnWidth($List1, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($List2, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_EndUpdate($List1)
    _GUICtrlListView_EndUpdate($List2)
    _GUICtrlListView_EndUpdate($List3)
EndFunc   ;==>Repaint

Func Quit()
    _GUICtrlListView_UnRegisterSortCallBack($List1)
    _GUICtrlListView_UnRegisterSortCallBack($List2)
    _GUICtrlListView_UnRegisterSortCallBack($List3)
    Exit
EndFunc   ;==>Quit

Func GUI()
    Local $Index, $LV1, $LV2, $LV3, $L1_EX, $L2_EX, $L3_EX
    $GUIhandle = GUICreate("ArchServer", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    $List1 = GUICtrlCreateListView( "Computer Name ", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_1, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT)
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $List2 = GUICtrlCreateListView("Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_2, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT)
    $List3 = GUICtrlCreateListView( "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_3, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $ActiveConnections = GUICtrlCreateList("0", 625, 486, 30, 30) ;dynamically updating list of connections as they come in
    GUICtrlSetResizing($ActiveConnections, $GUI_DOCKSIZE)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window
    For $Index = 0 To 10 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, _
            $ceLines, $cl
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Local Const $iLines = _SendMessage($List1, $LVM_GETTOPINDEX) - _SendMessage($List2, $LVM_GETTOPINDEX)
    _SendMessage($List2, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    _SendMessage($List3, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    Switch $hWndFrom
        Case $List1
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List1)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List2
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List2)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List3
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List3)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
    _Resize_ListViews()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)
    Const $SC_MAXIMIZE = 0xF030
    Const $SC_RESTORE = 0xF120
    Switch $wParam
        Case $SC_MAXIMIZE, $SC_RESTORE
            $bSysMsg = True
    EndSwitch
EndFunc   ;==>_WM_SYSCOMMAND

Func _Resize_ListViews()
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_1)
    WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_2)
    WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_3)
    WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
EndFunc   ;==>_Resize_ListViews
;========RESIZE FUNCTIONALITY THANKS TO MELBA

 

While this did enable sorting on XP. It also disabled scrolling on both XP and win 7 and disabled sorting on win 7, so unfortunately I think there is some problems using regular AutoIt ListView creation.

EDIT: Okay, my mistake on the win 7 sorting. Just need to figure out how to do scrolling and (had to use handles instead of CtrlID returned from creation of ListView) highlighting of characters in WM_Notify as it seems it is no longer called with regular AutoIt ListView interaction.

EDIT 2: Alright, got it figured out, it was due to the fact I was not using the handle instead I was using the CtrlID. BrewMan's solution thus solved my problems!

My thanks goes to you BrewManNH! :D

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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
Sign in to follow this  

  • Similar Content

    • careca
      By careca
      Hi, i have this array of numbers in the form of strings, and i assumed _arraysort would sort them out, but theres no option to do it numerically, so i had to do it another way, seems clumsy, what am i missing here? There's for sure a better way to sort this out numerically right? _arraysort is doing a mess with the numbers, it goes like this: 35,45,50,42,48,54
      #include<Array.au3> Local $ID, $AM Local $FO = Fileopen('mult.txt') Local $FR = FileReadToArray($FO) FileClose($FO) _ArrayDisplay($FR) For $d = 0 To UBound($FR) $AM = _ArrayMin($FR, 1) ConsoleWrite($AM &@CRLF) $ID = _ArraySearch($FR, $AM) _ArrayDelete($FR, $ID) Next So this way i retrieve the lowest number and then delete it from the array, what would you do?
      mult.txt
    • ternal
      By ternal
      Hi,
      Recently I have had the need to do a sort and then do a second sort while the item of the first sort stays the same ( double sorting , first on column x then while column x is the same sort column y).
      I did not put much efffort into error checking but so far I did not need it.
      For my applications so far it works perfectly however if someone is willing I want to test this extensivly.
      If anyone has big lists of random stuff to sort could you try this out please?
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArraySort_Double ; Description ...: ; Syntax ........: _ArraySort_Double (Byref $array[, $first_index = Default[, $second_index = Default[, $ascending = Default]]]) ; Parameters ....: $array - 2d array to sort. ; $first_index - [optional] first column to sort. Default is 0. ; $second_index - [optional] second column to sort. Default is 1. ; $ascending - [optional] ascending/descending. Default is 1. ; Return values .: 1 if no errors occured , -1 if errors occured ; Author ........: Ternal ; Remarks .......: Needs excessive testing. ; Related .......: _arraysort() ; =============================================================================================================================== Func _ArraySort_Double (byref $array, $first_index = Default, $second_index = Default, $ascending = Default) Local $temp_value Local $counter = 1 If UBound($array, $UBOUND_DIMENSIONS) <> 2 Then MsgBox(0, "error", "error") return -1 EndIf If $first_index = Default Then $first_index = 0 If $second_index = Default Then $second_index = 1 If $ascending = Default Then $ascending = 1 _ArraySort($array, $ascending, 0, 0, $first_index); you can alter settings of primary sort here If @error Then MsgBox(0, "error", @error) return -1 EndIf $temp_value = $array[0][$first_index] For $x = 1 to UBound($array, 1) - 1 If Mod( $x, 10000) = 0 Then ConsoleWrite("at " & $x & " of a total : " & UBound($array, 1) & @CRLF) If $array[$x][$first_index] = $temp_value Then $counter+= 1 If $x = UBound($array, 1) - 1 Then; do last line here(if last line is not a new item) _ArraySort($array, $ascending, $x - $counter, $x, $second_index);you can alter settings of secondary sort here(don't forget to place line 34 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf EndIf Else If $counter > 0 Then ;at least 2 of the same _ArraySort($array, $ascending, $x - $counter, $x - 1, $second_index);you can alter settings of secondary sort here(don't forget to place line 29 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf $counter = 1 EndIf EndIf $temp_value = $array[$x][$first_index] Next Return 1 EndFunc Kind regards, Ternal
    • Broihon
      By Broihon
      Hey guys,

      I ran into a problem when I wanted to delete items of a listview using the delete key. My approach is to register my own WndProc for the listview and then filter the $WM_GETDLGCODE msg and then call the original WndProc.
      That works like a charm. The problem is that when the listview gets redrawn it somehow ends up in an infinite loop. The listview is suddenly emtpy and I can't interact with any controls of the GUI at all. Here's the code:
       
      #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WinAPI.au3> $h_GUI = GUICreate("Test", 200, 200, 350, 350) $h_LV = GUICtrlCreateListView("Col 1|Col 2|Col 3", 0, 0, 200, 200) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 0) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 1) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 0) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 1) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 0) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 1) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 0) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 1) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 2) $h_LV_NewWndProc = DllCallbackRegister("WndProc_LV", "int", "hwnd;uint;wparam;lparam") $g_LV_OldWndProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($h_LV), $GWL_WNDPROC, DllCallbackGetPtr($h_LV_NewWndProc)) GUISetState(@SW_SHOW) Func WndProc_LV($hWnd, $uMsg, $wParam, $lParam) Return _WinAPI_CallWindowProc($g_LV_OldWndProc, $hWnd, $uMsg, $wParam, $lParam) EndFunc ;==>WndProc_GUI Do Until GUIGetMsg() = $GUI_EVENT_CLOSE DllCallbackFree($h_LV_NewWndProc) As you can see I'm doing nothing in the WndProc of the listview. I'm simply calling the original WndProc. This still "freezes" when I mess with the width of the columns or in the original project when I add more items that they don't fit in the listview and I have to scroll. If I don't do that it's working fine.
    • c.haslam
      By c.haslam
      I have
      Local $idListview = GUICtrlCreateListView("",8,8,@DesktopWidth/2-16,@DesktopHeight-150,$LVS_SHOWSELALWAYS, _ $LVS_EX_INFOTIP) Local $hListView = GUICtrlGetHandle($idListview) _GUICtrlListView_InsertColumn($hListview, 0, "Filename", 400) _GUICtrlListView_InsertColumn($hListview, 1, "Ext", 50) _GUICtrlListView_InsertColumn($hListview, 2, "Size",70) _GUICtrlListView_InsertColumn($hListview, 3, 'Date time',100) _GUICtrlListView_InsertColumn($hListview, 4, "Path", 385) _GUICtrlListView_InsertColumn($hListview, 5, "sizeInt", 0) _GUICtrlListView_JustifyColumn($hListview, $kSize,1) ; right align then further on
      While True $sFnamExt = FileFindNextFile($iSrch) If @error Then ExitLoop EndIf $sAtts = FileGetAttrib($sPath&'\'&$sFnamExt) If StringInStr($sAtts,'D') Then If $sFnamExt<>'$RECYCLE.BIN' Then $sDirs &= '?'&$sPath&'\'&$sFnamExt EndIf Else $p = StringInStr($sFnamExt,'.',0,-1) ; last If $p=0 Then $sFnam = $sFnamExt $sExt = '' Else $sFnam = StringLeft($sFnamExt,$p-1) $sExt = StringTrimLeft($sFnamExt,$p) EndIf _GUICtrlListView_AddItem($hListview,$sFnam,-1,_GUICtrlListView_GetItemCount($hListview)+1000) _GUICtrlListView_AddSubItem($hListview,$nItem,$sExt,$kExt) $nSize = FileGetSize($sPath&'\'&$sFnamExt) $sSize = AddThousandsSeparator($nsize) _GUICtrlListView_AddSubItem($hListview,$nItem,$sSize,$kSize) _GUICtrlListView_AddSubItem($hListview,$nItem,$nsize,$kSizeInt) $nTotBytes += $nSize $a1 = FileGetTime($sPath&'\'&$sFnamExt,$FT_MODIFIED,$FT_ARRAY) $t = $a1[0]&'-'&$a1[1]&'-'&$a1[2]&' '&$a1[3]&':'&$a1[4] _GUICtrlListView_AddSubItem($hListview,$nItem,$t,$kDateTime) _GUICtrlListView_AddSubItem($hListview,$nItem,$sPath,$kPath) If $gSQL Then $s = "Insert into tbl values ("&_SQLite_Escape($sFnam)&","&_SQLite_Escape($sExt)&",'"& _ $sSize&"','"& _ $t&"',"&_SQLite_Escape($sPath)&","&$nSize&")" _SQLite_Exec(-1,$s) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf EndIf EndIf WEnd FileClose($iSrch) You will see that I heeded the advice in Help > _GUICtrlListView_AddItem: "As AutoIt uses the $iParam parameter to store the controlID of native-created ListView items, this value should be set sufficiently high for UDF-created items to avoid possible conflict with any existing controls - a starting value of 1000 is recommended."
      (It's unfortunate that the Example does not heed this advice. OK, it doesn't need to because there are no other controls, but still --- it would help neophytes if it did. Also to me _GUICtrlListView_AddItem is not native because it is a UDF. Confused?)
      My script then does a sort using SQLite, and updates the ListView:
      Local $hQuery Local $colNames = ['fnam','ext','nsize','dateTime','path','SizeInt'] Local $s = "Select * FROM tbl ORDER BY "&$colNames[$ncol]&';' _SQLite_Query(-1,$s, $hQuery) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf Local $aRow[$kSizeInt+1] Local $iItem=-1 While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf $iItem += 1 For $i = $kFnam To $kSizeInt _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default) Next WEnd This works, but I had earlier coded
      _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default,$iItem+1000) because the same advice is in the Help for this function.
      So my care in specifying $param back-fired! What am I not understanding?
      The only difference in what works is that the $param parameter is defaulted.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am building a management for the company I work with, and I just imported a real amount of rows ( about 29000 ), in my SQLite DB.
      The thing I am not understanding, is the time that the script takes to build this amount of rows in the ListView.
      I didn't measure it, but I think it took 2 minutes or so to create each ListView item...
      It is normal that it takes so much time?
      What can I do to improve the creation of the items?

      Here's the code I am using to query and to create ListView items...
      ; Articles ListView: Global $lvwArticles = GUICtrlCreateListView("ID|Fornitore|Codice|Descrizione|EU|Prezzo|Sconto Applicato|Note", 14, 87, 1507, 660, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_SORTDESCENDING), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) ; Query $strQuery = "SELECT * FROM ARTICOLI;" ; Query Execution _SQLite_GetTable2d($objDatabase, $strQuery, $arrResult, $intRows, $intColumns) If @error Then ; Error Handling Else ; Cleaning the ListView _GUICtrlListView_DeleteAllItems($lvwArticles) If @error Then ; Error Handling Else ; No records in the Table If UBound($arrResult) < 2 Then ; Error Handling Else _GUICtrlListView_BeginUpdate($lvwArticles) For $intCounter = 1 To UBound($arrResult) - 1 $strListViewItem = $arrResult[$intCounter][0] & "|" & _ $arrResult[$intCounter][1] & "|" & _ $arrResult[$intCounter][2] & "|" & _ $arrResult[$intCounter][3] & "|" & _ $arrResult[$intCounter][4] & "|" & _ $arrResult[$intCounter][5] & "|" & _ $arrResult[$intCounter][6] & "|" & _ $arrResult[$intCounter][7] $objListViewItem = GUICtrlCreateListViewItem($strListViewItem, $lvwArticles) Next _GUICtrlListView_EndUpdate($lvwArticles) EndIf EndIf EndIf Thanks in advance


      Best Regards.
×