Jump to content

Questions about Drag and Drop


MISIIM
 Share

Recommended Posts

  • How do I get all the filenames if more than one file was dropped?
  • How do I have a ListViewItem be dropped on another ListViewItem in the same ListView?
Thanks.

For the file names if more than one file dropped search for 'DragQueryFile'.

What do you want to happen when you try to drop one item onto another in a listview?

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.
Link to comment
Share on other sites

It is for a file manager. If one drops a file/folder on a folder have it be moved to that folder.

Maybe a Treeview would be easier, but can you show what you've got so far?

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.
Link to comment
Share on other sites

It is really long. I mean really really long. I have no code at all to do the d&d except to copy/move files to the folder.

OK. Could you at least give an idea of how the information is arranged in the listview, or a screenshot maybe?

For example, are there 2 columns with folders in the left and files in the right?

EDIT:

Second thoughts, what you need to do is to produce a simple script which shows the listview with something in it so that we have something to work on, otherwise you're asking us to produce a solution to an unknown problem which means at least one person could waste a lot of time. Of course some questions don't need example scripts, but in this case you seem to be saying you can't produce a script to show what you're trying to do so could someone else do it. Maybe someone will but for me I need something from you first.

Edited by martin
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.
Link to comment
Share on other sites

Here it is. I need to be able to drag file(s) onto a directory. I can handle the rest after that.

Edit: Forgot code

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1);

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

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);

While True
    Sleep(200);
WEnd

Func window_Close()
    Exit(0);
EndFunc
Edited by MISIIM
Link to comment
Share on other sites

Here it is. I need to be able to drag file(s) onto a directory. I can handle the rest after that.

Edit: Forgot code

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1);

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

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);

While True
    Sleep(200);
WEnd

Func window_Close()
    Exit(0);
EndFunc

Try this, it should get you started.

#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 iver 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 < 1 Then Return
            $SelItems = _GUICtrlListViewGetSelectedIndices($listview);the list of the items 
            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)
                MsgBox(0,'You need to write code to copy item(s)' & $selitems,'to item no.' & $ToItem)
                
            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.
Link to comment
Share on other sites

thanks Martin!

I just did the following:

;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)
                ;MsgBox(0,'You need to write code to copy item(s)' & $selitems,'to item no.' & $ToItem)
                Local $fromText = _GUICtrlListViewGetItemText($listview,$selitems)
                Local $toText = _GUICtrlListViewGetItemText($listview,$ToItem)
                _GUICtrlListViewInsertItem ( $listview, $ToItem, $fromText)
                _GUICtrlListViewDeleteItem( $listview,$selitems+1)
            EndIf
A decision is a powerful thing
Link to comment
Share on other sites

thanks Martin!

I just did the following:

;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)
                ;MsgBox(0,'You need to write code to copy item(s)' & $selitems,'to item no.' & $ToItem)
                Local $fromText = _GUICtrlListViewGetItemText($listview,$selitems)
                Local $toText = _GUICtrlListViewGetItemText($listview,$ToItem)
                _GUICtrlListViewInsertItem ( $listview, $ToItem, $fromText)
                _GUICtrlListViewDeleteItem( $listview,$selitems+1)
            EndIf
Glad it helped. It might be that

MouseClick("left");click to select the target item
$ToItem = _GUICtrlListViewGetSelectedIndices($listview)

could be reduced to

$ToItem = _GUICtrlListViewGetHotItem($listview)

though I haven't tried it.

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.
Link to comment
Share on other sites

Couldn't get that to work.

You're right, so guessing doesn't always work then.

BTW you will need to change your code depending on whether you are dragging an item down or up, or you delete the wrong item.

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.
Link to comment
Share on other sites

You're right, so guessing doesn't always work then.

BTW you will need to change your code depending on whether you are dragging an item down or up, or you delete the wrong item.

OOOOOOHHHH good point! I'm a moron! thank you :)

A decision is a powerful thing
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...