Jump to content
Sign in to follow this  
Champak

Listview items reversed once moved to different point

Recommended Posts

Champak

Hopefully this is something simple that I'm just not seeing. Focus on the _MoveMe function. When I input a destination to move items to in the listview, and the items are at a lower indices than the final destination, everything is fine. But if the source rows are at a higher indices point that the final destination, the order of the items are reversed once they are moved. How do I fix this?

#include <GUIConstants.au3>
#include <GUIListView.au3>


Opt("GUIOnEventMode", 1)

Global $TotalList[0]

$hGUI = GUICreate("MyGUI")

$iLw1 = GUICtrlCreateListView("Col1|Col2", 10, 10, 320, 320, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

For $i = 1 To 58
    GUICtrlCreateListViewItem($i & "|" & Chr($i + 64), $iLw1)
Next

$Index = GUICtrlCreateInput("", 200, 340, 50, 50)

$Button = GUICtrlCreateButton("Insert", 20, 340, 70, 70)
GUICtrlSetOnEvent(-1, "_MoveMe")

$ButtonE = GUICtrlCreateButton("Exit", 120, 340, 70, 70)
GUICtrlSetOnEvent(-1, "_Exit")

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

While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd

Func _MoveMe()

$Point = GUICtrlRead($Index)
$J = 0
    For $i = 0 To UBound($TotalList) - 1

        If $Point > Number($TotalList[$i]) Then

            ConsoleWrite("- Less than input" & @CRLF)
            $OIndex = _GUICtrlListView_GetItemText ( $iLw1, Number($TotalList[$i]) - $J )
            $1Index = _GUICtrlListView_GetItemText ( $iLw1, Number($TotalList[$i]) - $J , 1)
            _GUICtrlListView_InsertItem ( $iLw1, $OIndex, $Point)
            _GUICtrlListView_SetItemText ( $iLw1, $Point, $1Index, 1)
            _GUICtrlListView_DeleteItem ( $iLw1, Number($TotalList[$i]) - $J )

            $J += 1
        Else

            ConsoleWrite("+ Greater than input" & @CRLF)
            $OIndex = _GUICtrlListView_GetItemText ( $iLw1, Number($TotalList[$i]) )
            $1Index = _GUICtrlListView_GetItemText ( $iLw1, Number($TotalList[$i]) , 1)
            _GUICtrlListView_DeleteItem ( $iLw1, Number($TotalList[$i]) )
            _GUICtrlListView_InsertItem ( $iLw1, $OIndex, $Point)
            _GUICtrlListView_SetItemText ( $iLw1, $Point, $1Index, 1)

        EndIf
    Next

EndFunc

Func _Exit()
    Exit
EndFunc


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $LV_Add = True
    Local $LV_Exit = False

    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    Local $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $iLw1
            Switch $iCode
                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    Local $iIndex = DllStructGetData($tInfo, "Index")

            ;       _GUICtrlListView_BeginUpdate ( $iLw1 )


                    $ListArray = _GUICtrlListView_GetSelectedIndices ($iLw1)


                    For $i = UBound($TotalList) - 1 To 0 Step - 1
                        If $TotalList[$i] = $ListArray Then
                            ConsoleWrite("--" & $i & "--" & $TotalList[$i] & @CRLF)

                            If UBound($TotalList) = 1 Then
                                $LV_Exit = True
                                Sleep(1000);==The last item wont unhilight unless this is here
                            EndIf

                            _ArrayDelete($TotalList, $i)
                            _GUICtrlListView_SetItemSelected ($iLw1, Number($ListArray), False)
                            $LV_Add = False
                            If $LV_Exit = True Then
                                $LV_Exit = False
                                Return
                            EndIf
                        EndIf
                    Next


                    If $LV_Add = True Then _ArrayAdd($TotalList, $ListArray)


                    ConsoleWrite("----------" & @CRLF)


                    If UBound($TotalList) >= 1 Then
                        For $j = 0 to UBound($TotalList) - 1
                            $444 = _GUICtrlListView_SetItemSelected($iLw1, Number($TotalList[$j]))
                            ConsoleWrite(">>> " & $j & "___" & $TotalList[$j] & "___" & $444 & @CRLF)
                        Next
                    EndIf

            ;       _GUICtrlListView_EndUpdate ( $iLw1 )

                    ;_ArrayDisplay($TotalList)
                  ;  AdlibRegister("MyFunc", 0)
            EndSwitch
    EndSwitch


    Return $GUI_RUNDEFMSG
EndFunc

#cs
Func MyFunc()
    AdlibUnRegister("MyFunc")
    Local Static $fCall = False
    If $fCall Then Return 0
    $fCall = True
    _ArrayDisplay($TotalList) ;make $Totallist as global
    $fCall = False
EndFunc
#ce

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  

×