Jump to content

_GUICtrlListView_SimpleSort / Odd behavior


 Share

Go to solution Solved by Melba23,

Recommended Posts

For some reason when I use simple sort on a list view that has checkboxes it will check the 0 index item, but only seems to do so once.  I'm hoping someone else has seen this and addressed it somewhat elegantly becuase I'd rather not modify the include if possible.  I'd appreciate someone else checking it out to see if it's something I'm doing or an unexpected behavior.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work
Global $hListView, $B_DESCENDING
_Main()
Func _Main()
 GUICreate("ListView SimpleSort", 400, 300)
 $hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268)
 _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
 GUICtrlCreateListViewItem("line4|5|more_a", $hListView)
 GUICtrlCreateListViewItem("line5|4.50 |more_c", $hListView)
 GUICtrlCreateListViewItem("line5|4.0 |more_c", $hListView)
 GUICtrlCreateListViewItem("line3|23|more_e", $hListView)
 GUICtrlCreateListViewItem("line2|0.34560 |more_d", $hListView)
 GUICtrlCreateListViewItem("line1|1.0 |more_b", $hListView)
 GUICtrlCreateListViewItem("line1|0.1 |more_b", $hListView)
 GUICtrlCreateListViewItem("line1|10|more_b", $hListView)
 _GUICtrlListView_SetColumnWidth($hListView, 0, 75)
 _GUICtrlListView_SetColumnWidth($hListView, 1, 75)
 _GUICtrlListView_SetColumnWidth($hListView, 2, 75)
 GUISetState()
 GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
 Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]
 ; Loop until user exits
 Do
 Until GUIGetMsg() = $GUI_EVENT_CLOSE
 GUIDelete()
EndFunc   ;==>_Main
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
 #forceref $hWnd, $iMsg, $iwParam
 Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
 $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 $LVN_COLUMNCLICK ; A column was clicked
     $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
     _DebugPrint("$LVN_COLUMNCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode & @LF & _
       "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
       "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
       "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
       "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
       "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
       "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
       "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
       "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
     _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
     ; No return value
    Case $LVN_KEYDOWN ; A key has been pressed
     $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
     _DebugPrint("$LVN_KEYDOWN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode & @LF & _
       "-->VKey:" & @TAB & DllStructGetData($tInfo, "VKey") & @LF & _
       "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags"))
     ; No return value
    Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
     _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode & @LF & _
       "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
       "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
       "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
       "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
       "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
       "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
       "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
       "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
       "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
     ; No return value
    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
     _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode & @LF & _
       "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
       "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
       "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
       "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
       "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
       "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
       "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
       "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
       "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
     ; No return value
    Case $NM_KILLFOCUS ; The control has lost the input focus
     _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode)
     ; No return value
    Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
     _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode & @LF & _
       "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
       "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
       "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
       "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
       "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
       "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
       "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
       "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
       "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
     ;Return 1 ; not to allow the default processing
     Return 0 ; allow the default processing
    Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button
     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
     _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode & @LF & _
       "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
       "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
       "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
       "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
       "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
       "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
       "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
       "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
       "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
     ; No return value
    Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
     _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode)
     ; No return value
    Case $NM_SETFOCUS ; The control has received the input focus
     _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
       "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
       "-->Code:" & @TAB & $iCode)
     ; No return value
   EndSwitch
 EndSwitch
 Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
 ConsoleWrite( _
   "!===========================================================" & @LF & _
   "+======================================================" & @LF & _
   "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
   "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
Link to comment
Share on other sites

  • Moderators
  • Solution

spudw2k,

What AutoIt version are you running? That bug was fixed quite a while ago - it is certainly not present in v3.3.12.0. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

What AutoIt version are you running?

An old one. :P v3.3.8.1

I never think to try a new version.  Maybe I need to get in the habit of reading the changelog.  I'll take your word for it and mark this one solved.

Thank you sir.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...