Sign in to follow this  
Followers 0
dcop

Drag Lines

4 posts in this topic

I'd like to take a file list that I create and put it in a listview or an _arraydisplay, which I do, but then be able to drag a line up or down. Basically putting them in different order in the list. Please point to some options, I been messing with it.

TIA, Dennis

Share this post


Link to post
Share on other sites



I'd like to take a file list that I create and put it in a listview or an _arraydisplay, which I do, but then be able to drag a line up or down. Basically putting them in different order in the list. Please point to some options, I been messing with it.

TIA, Dennis

This is an example I did for someone which was edited by JohnBailey

#include <GUIConstants.au3>
#include <guilistview.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1);

Dim $window = GUICreate("", 500, 400,400,400)
Dim $listview = GUICtrlCreateListView("filename", 0, 0, 450, 350,BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS));

GUICtrlCreateListViewItem("..", $listview);
GUICtrlCreateListViewItem("dir1", $listview);
GUICtrlCreateListViewItem("dir2", $listview);
GUICtrlCreateListViewItem("dir3", $listview);
GUICtrlCreateListViewItem("file1.txt", $listview);
GUICtrlCreateListViewItem("file2.dat", $listview);
GUICtrlCreateListViewItem("file3.ini", $listview);
GUICtrlCreateListViewItem("file4.png", $listview);
GUISetOnEvent($GUI_EVENT_CLOSE, "window_Close", $window);
GUISetState(@SW_SHOW, $window);

GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"MyHandler");<---------

While True
    Sleep(200);
WEnd

Func window_Close()
    Exit(0);
EndFunc


Func MyHandler();<---------------------
;where was the cursor when the button was pressed?
    $Info =  GUIGetCursorInfo (WinGetHandle($window))
    If $Info[4] = $listview Then;if it was over the listview
        If _IsPressed(1) Then;if the left mouse button pressed(must be really or how did we get here)
            $noSel = _GUICtrlListViewGetSelectedCount($listview);the number of selected items being dragged
            If $noSel = $LV_ERR Then Return
            $SelItem = _GUICtrlListViewGetSelectedIndices($listview,1);the list of the items
            $SelItem = $SelItem[1];only allow one item to br dragged in this example
            While _IsPressed(1)
                
            ;wait for dragging to stop

            WEnd
            
        ;where is the cursor now?
            $Info =  GUIGetCursorInfo (WinGetHandle($window))
            If $Info[4] = $listview Then;if it's still over the listview
                MouseClick("left");click to select the target item
                $ToItem = _GUICtrlListViewGetSelectedIndices($listview)
                
                Local $fromText = _GUICtrlListViewGetItemText($listview,$selitem)
                Local $toText = _GUICtrlListViewGetItemText($listview,$ToItem)
                _GUICtrlListViewInsertItem ( $listview, $ToItem, $fromText)
                If $SelItem > $ToItem Then
                    _GUICtrlListViewDeleteItem( $listview,$selitem+1)
                Else
                    _GUICtrlListViewDeleteItem( $listview,$selitem)
                EndIf
            EndIf
        EndIf
    EndIf

EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

This is an example I did for someone which was edited by JohnBailey

#include <GUIConstants.au3>
#include <guilistview.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1);

Dim $window = GUICreate("", 500, 400,400,400)
Dim $listview = GUICtrlCreateListView("filename", 0, 0, 450, 350,BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS));

GUICtrlCreateListViewItem("..", $listview);
GUICtrlCreateListViewItem("dir1", $listview);
GUICtrlCreateListViewItem("dir2", $listview);
GUICtrlCreateListViewItem("dir3", $listview);
GUICtrlCreateListViewItem("file1.txt", $listview);
GUICtrlCreateListViewItem("file2.dat", $listview);
GUICtrlCreateListViewItem("file3.ini", $listview);
GUICtrlCreateListViewItem("file4.png", $listview);
GUISetOnEvent($GUI_EVENT_CLOSE, "window_Close", $window);
GUISetState(@SW_SHOW, $window);

GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"MyHandler");<---------

While True
    Sleep(200);
WEnd

Func window_Close()
    Exit(0);
EndFunc
Func MyHandler();<---------------------
;where was the cursor when the button was pressed?
    $Info =  GUIGetCursorInfo (WinGetHandle($window))
    If $Info[4] = $listview Then;if it was over the listview
        If _IsPressed(1) Then;if the left mouse button pressed(must be really or how did we get here)
            $noSel = _GUICtrlListViewGetSelectedCount($listview);the number of selected items being dragged
            If $noSel = $LV_ERR Then Return
            $SelItem = _GUICtrlListViewGetSelectedIndices($listview,1);the list of the items
            $SelItem = $SelItem[1];only allow one item to br dragged in this example
            While _IsPressed(1)
                
        ;wait for dragging to stop

            WEnd
            
    ;where is the cursor now?
            $Info =  GUIGetCursorInfo (WinGetHandle($window))
            If $Info[4] = $listview Then;if it's still over the listview
                MouseClick("left");click to select the target item
                $ToItem = _GUICtrlListViewGetSelectedIndices($listview)
                
                Local $fromText = _GUICtrlListViewGetItemText($listview,$selitem)
                Local $toText = _GUICtrlListViewGetItemText($listview,$ToItem)
                _GUICtrlListViewInsertItem ( $listview, $ToItem, $fromText)
                If $SelItem > $ToItem Then
                    _GUICtrlListViewDeleteItem( $listview,$selitem+1)
                Else
                    _GUICtrlListViewDeleteItem( $listview,$selitem)
                EndIf
            EndIf
        EndIf
    EndIf

EndFunc

Works Great!

Thanx Martin!

Share this post


Link to post
Share on other sites

Only problem I can see is if you don't drop it on top of another item, it duplicates it, but that's not a big deal. Otherwise, great script!

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  
Followers 0