Jump to content

Listview ENDDRAG wrong result


MyEarth
 Share

Recommended Posts

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

$Form = GUICreate("Form", 346, 280, 192, 124)
$iListView = GUICtrlCreateListView("A|B|C|D|", 8, 8, 329, 257)
$hListview = GUICtrlGetHandle($iListView)
$hHeader =_GUICtrlListView_GetHeader($iListview)

GUICtrlSendMsg($iListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, 0, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP))

GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 50)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode
    Local $tNMHDR, $tNMHEADER, $tNMHDFILTERBTNCLICK, $tNMHDDISPINFO

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hHeader
            Switch $iCode
                Case $HDN_ENDDRAG ; Sent by a header control when a drag operation has ended on one of its items
                    $tNMHEADER = DllStructCreate($tagNMHEADER, $ilParam)
;~                     ConsoleWrite("$HDN_ENDDRAG" & @LF & "--> hWndFrom:" & @TAB & DllStructGetData($tNMHEADER, "hWndFrom") & @LF & _
;~                             "-->IDFrom:" & @TAB & DllStructGetData($tNMHEADER, "IDFrom") & @LF & _
;~                             "-->Code:" & @TAB & DllStructGetData($tNMHEADER, "Code") & @LF & _
;~                             "-->Item:" & @TAB & DllStructGetData($tNMHEADER, "Item") & @LF & _
;~                             "-->Button:" & @TAB & DllStructGetData($tNMHEADER, "Button"))
                    Local $sColumnOrder = _GUICtrlListView_GetColumnOrder($iListView)
                    ConsoleWrite($sColumnOrder & @CRLF)
                    Return False ; To allow the control to automatically place and reorder the item
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Try to move the column D to C but is doing with whatever column. The result is:

0|1|2|3

But is wrong! The correct one is

0|1|3|2

$HDN_ENDDRAG ; Sent by a header control when a drag operation has ended on one of its items

So why since i'll do _GUICtrlListView_GetColumnOrder when is end the draggin operation i'll get the previus order of the column? What i have miss this time?

Link to comment
Share on other sites

  • Moderators

MyEarth,

As so often with ListViews, you need to wait for the handler to exit before getting the new column order:

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

Global $fColDrag = False

$Form = GUICreate("Form", 346, 280, 192, 124)
$iListView = GUICtrlCreateListView("A|B|C|D|", 8, 8, 329, 257)
$hListview = GUICtrlGetHandle($iListView)
$hHeader =_GUICtrlListView_GetHeader($iListview)

GUICtrlSendMsg($iListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, 0, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP))

GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 50)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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

    If $fColDrag Then
        $fColDrag = False
        Local $sColumnOrder = _GUICtrlListView_GetColumnOrder($iListView)
        ConsoleWrite($sColumnOrder & @CRLF)
    EndIf


WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode
    Local $tNMHDR, $tNMHEADER, $tNMHDFILTERBTNCLICK, $tNMHDDISPINFO

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hHeader
            Switch $iCode
                Case $HDN_ENDDRAG ; Sent by a header control when a drag operation has ended on one of its items
                    $fColDrag = True
                    Return False ; To allow the control to automatically place and reorder the item
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

That works fine for me.

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

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...