Jump to content

DragDrop ListView Elements with Multiple ListViews in GUI


Recommended Posts

As you can see below, I'm trying to enable the ability to drag listview items from one side to the other (which I did) and then back again (which I can't seem to do). The problem seems to be that using the GUISetOnEvent($GUI_EVENT_DROPPED, "funcName") is limiting. What I need is each listview to be a "hitspot" of sorts. I looked through msdn to find a listview mouse click release (which I couldn't find) and then use gaFrosts method of clicking the listview elements. This ended in a dead end for me. There may be a way to do all of this through MouseGetPos () method and create pseudo hit spots. I don't really know the best way.

#include <GuiConstants.au3>
#include <GuiListView.au3>

Opt ("GUIOnEventMode", 1)


Global $LV_DragFromHere, $LV_DropToHere
#Region ### START Koda GUI section ### Form=I:\SAI\Auto-It files\Experiments\Foundations\LV - DragDrop Save Changes (two LVs).kxf
$ParentWin = GUICreate("Copy Example", 730, 447, 193, 115)
$LV_DragFromHere = GUICtrlCreateListView("Name|Number", 23, 30, 249, 399) ;BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)
_GUICtrlListViewSetColumnWidth ($LV_DragFromHere, 0, 120)
_GUICtrlListViewSetColumnWidth ($LV_DragFromHere, 1, 120)
GUICtrlSendMsg($LV_DragFromHere, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

For $x = 1 to Random(5,20,1)
    GUICtrlCreateListViewItem(_CreateRanNameish()&"|"&Random(100000,999999,1), $LV_DragFromHere)
Next

$LV_DropToHere = GUICtrlCreateListView("Name|Number", 289, 30, 249, 399)
_GUICtrlListViewSetColumnWidth ($LV_DropToHere, 0, 120)
_GUICtrlListViewSetColumnWidth ($LV_DropToHere, 1, 120)
Global $TotalColumns = 2
GUICtrlSetState($LV_DropToHere,$GUI_DROPACCEPTED)
GUICtrlSetState($LV_DragFromHere,$GUI_DROPACCEPTED)
GUISetOnEvent($GUI_EVENT_DROPPED, "_MoveRight")
;GUISetOnEvent($GUI_EVENT_DROPPED, "_MoveLeft")

$Label1 = GUICtrlCreateLabel("Drag From Here", 24, 11, 79, 17)
$Label2 = GUICtrlCreateLabel("Drop To Here", 288, 10, 69, 17)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(15)
WEnd

Func _CreateRanNameish()
    Local $Nameish = ''
    For $i = 1 to Random(4,12,1)
        $Nameish &= chr(Random(65,90,1))
    Next
    Return $Nameish
EndFunc


Func _CopyRight()
    _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere)
EndFunc   ;==>_CopyRight

Func _MoveRight()
    _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere, 1)
EndFunc   ;==>_MoveRight

Func _CopyLeft()
    _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere)
EndFunc   ;==>_CopyLeft

Func _MoveLeft()
    _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere, 1)
EndFunc   ;==>_MoveLeft


Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            _Exit()
    EndSelect
EndFunc   ;==>SpecialEvents
A decision is a powerful thing
Link to comment
Share on other sites

As you can see below, I'm trying to enable the ability to drag listview items from one side to the other (which I did) and then back again (which I can't seem to do). The problem seems to be that using the GUISetOnEvent($GUI_EVENT_DROPPED, "funcName") is limiting. What I need is each listview to be a "hitspot" of sorts. I looked through msdn to find a listview mouse click release (which I couldn't find) and then use gaFrosts method of clicking the listview elements. This ended in a dead end for me. There may be a way to do all of this through MouseGetPos () method and create pseudo hit spots. I don't really know the best way.

#include <GuiConstants.au3>
#include <GuiListView.au3>

Opt ("GUIOnEventMode", 1)
Global $LV_DragFromHere, $LV_DropToHere
#Region ### START Koda GUI section ### Form=I:\SAI\Auto-It files\Experiments\Foundations\LV - DragDrop Save Changes (two LVs).kxf
$ParentWin = GUICreate("Copy Example", 730, 447, 193, 115)
$LV_DragFromHere = GUICtrlCreateListView("Name|Number", 23, 30, 249, 399) ;BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)
_GUICtrlListViewSetColumnWidth ($LV_DragFromHere, 0, 120)
_GUICtrlListViewSetColumnWidth ($LV_DragFromHere, 1, 120)
GUICtrlSendMsg($LV_DragFromHere, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

For $x = 1 to Random(5,20,1)
    GUICtrlCreateListViewItem(_CreateRanNameish()&"|"&Random(100000,999999,1), $LV_DragFromHere)
Next

$LV_DropToHere = GUICtrlCreateListView("Name|Number", 289, 30, 249, 399)
_GUICtrlListViewSetColumnWidth ($LV_DropToHere, 0, 120)
_GUICtrlListViewSetColumnWidth ($LV_DropToHere, 1, 120)
Global $TotalColumns = 2
GUICtrlSetState($LV_DropToHere,$GUI_DROPACCEPTED)
GUICtrlSetState($LV_DragFromHere,$GUI_DROPACCEPTED)
GUISetOnEvent($GUI_EVENT_DROPPED, "_MoveRight")
;GUISetOnEvent($GUI_EVENT_DROPPED, "_MoveLeft")

$Label1 = GUICtrlCreateLabel("Drag From Here", 24, 11, 79, 17)
$Label2 = GUICtrlCreateLabel("Drop To Here", 288, 10, 69, 17)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(15)
WEnd

Func _CreateRanNameish()
    Local $Nameish = ''
    For $i = 1 to Random(4,12,1)
        $Nameish &= chr(Random(65,90,1))
    Next
    Return $Nameish
EndFunc
Func _CopyRight()
    _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere)
EndFunc   ;==>_CopyRight

Func _MoveRight()
    _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere, 1)
EndFunc   ;==>_MoveRight

Func _CopyLeft()
    _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere)
EndFunc   ;==>_CopyLeft

Func _MoveLeft()
    _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere, 1)
EndFunc   ;==>_MoveLeft
Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            _Exit()
    EndSelect
EndFunc   ;==>SpecialEvents

This works but you might need to add some checks to make sure that the dragging started from the other listview. At the moment it is assumed that when something is dropped in one of the list views it comes from the other one.

#include <GuiConstants.au3>
#include <GuiListView.au3>

Opt ("GUIOnEventMode", 1)


Global $LV_DragFromHere, $LV_DropToHere
#Region ### START Koda GUI section ### Form=I:\SAI\Auto-It files\Experiments\Foundations\LV - DragDrop Save Changes (two LVs).kxf
$ParentWin = GUICreate("Copy Example", 730, 447, 193, 115)
$LV_DragFromHere = GUICtrlCreateListView("Name|Number", 23, 30, 249, 399);BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)
_GUICtrlListViewSetColumnWidth ($LV_DragFromHere, 0, 120)
_GUICtrlListViewSetColumnWidth ($LV_DragFromHere, 1, 120)
GUICtrlSendMsg($LV_DragFromHere, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

For $x = 1 to Random(5,20,1)
    GUICtrlCreateListViewItem(_CreateRanNameish()&"|"&Random(100000,999999,1), $LV_DragFromHere)
Next


$LV_DropToHere = GUICtrlCreateListView("Name|Number", 289, 30, 249, 399)
_GUICtrlListViewSetColumnWidth ($LV_DropToHere, 0, 120)
_GUICtrlListViewSetColumnWidth ($LV_DropToHere, 1, 120)
GUICtrlSendMsg($LV_DropToHere, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

Global $TotalColumns = 2
GUICtrlSetState($LV_DropToHere,$GUI_DROPACCEPTED)
GUICtrlSetState($LV_DragFromHere,$GUI_DROPACCEPTED)
GUISetOnEvent($GUI_EVENT_DROPPED, "Dropping")
;GUISetOnEvent($GUI_EVENT_DROPPED, "_MoveLeft")

$Label1 = GUICtrlCreateLabel("Drag From Here", 24, 11, 79, 17)
$Label2 = GUICtrlCreateLabel("Drop To Here", 288, 10, 69, 17)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(15)
WEnd

Func _CreateRanNameish()
    Local $Nameish = ''
    For $i = 1 to Random(4,12,1)
        $Nameish &= chr(Random(65,90,1))
    Next
    Return $Nameish
EndFunc



Func Dropping()
    ConsoleWrite("dropping" & @CRLF)
    $Mid = GUIGetCursorInfo (WinGetHandle($ParentWin))
    
Switch $Mid[4]
    Case $LV_DragFromHere
         _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere, 1)

    Case $LV_DropToHere
         _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere, 1)
        
EndSwitch
        
    
EndFunc

Func _CopyRight()
    _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere)
EndFunc  ;==>_CopyRight

Func _MoveRight()
    _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere, 1)
EndFunc  ;==>_MoveRight

Func _CopyLeft()
    _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere)
EndFunc  ;==>_CopyLeft

Func _MoveLeft()
    _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere, 1)
EndFunc  ;==>_MoveLeft


Func _Exit()
    Exit
EndFunc  ;==>_Exit

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            _Exit()
    EndSelect
EndFunc  ;==>SpecialEvents
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

Martin that rocks!! Such a small method too THANKS I added a check... let me know if it sucks :)

Func Dropping()
    ConsoleWrite("dropping" & @CRLF)
    $Mid = GUIGetCursorInfo (WinGetHandle($ParentWin))
    Switch $Mid[4]
        Case $LV_DragFromHere
            If @GUI_DragId = $LV_DropToHere AND @GUI_DropId = $LV_DragFromHere Then
                _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere, 1)
            EndIf
    
        Case $LV_DropToHere
            If @GUI_DragId = $LV_DragFromHere AND @GUI_DropId = $LV_DropToHere Then
                _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere, 1)
            EndIf
    EndSwitch
            
EndFunc
A decision is a powerful thing
Link to comment
Share on other sites

Martin that rocks!! Such a small method too THANKS I added a check... let me know if it sucks :)

Func Dropping()
    ConsoleWrite("dropping" & @CRLF)
    $Mid = GUIGetCursorInfo (WinGetHandle($ParentWin))
    Switch $Mid[4]
        Case $LV_DragFromHere
            If @GUI_DragId = $LV_DropToHere AND @GUI_DropId = $LV_DragFromHere Then
                _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere, 1)
            EndIf
    
        Case $LV_DropToHere
            If @GUI_DragId = $LV_DragFromHere AND @GUI_DropId = $LV_DropToHere Then
                _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere, 1)
            EndIf
    EndSwitch
            
EndFunc
Yep, that's good. I'd forgotten about @GUI_DropID and @GUI_DragID so now that you've done that you don't need my code.

Func Dropping()

   If (@GUI_DragId = $LV_DropToHere AND @GUI_DropId = $LV_DragFromHere) Or _
       (@GUI_DropId = $LV_DropToHere AND @GUI_DragId = $LV_DragFromHere) Then
        _GUICtrlListViewCopyItems ( @GUI_DragId,@GUI_DropId, 1)
    EndIf
    
EndFunc
EndFunc
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

Yep, that's good. I'd forgotten about @GUI_DropID and @GUI_DragID so now that you've done that you don't need my code.

Func Dropping()

   If (@GUI_DragId = $LV_DropToHere AND @GUI_DropId = $LV_DragFromHere) Or _
       (@GUI_DropId = $LV_DropToHere AND @GUI_DragId = $LV_DragFromHere) Then
        _GUICtrlListViewCopyItems ( @GUI_DragId,@GUI_DropId, 1)
    EndIf
    
EndFunc
EndFunc

SO TIGHT!!! I didn't even think of that !!! Thanks Martin! This rocks

A decision is a powerful thing
Link to comment
Share on other sites

  • 2 weeks later...

Yep, that's good. I'd forgotten about @GUI_DropID and @GUI_DragID so now that you've done that you don't need my code.

Func Dropping()

   If (@GUI_DragId = $LV_DropToHere AND @GUI_DropId = $LV_DragFromHere) Or _
       (@GUI_DropId = $LV_DropToHere AND @GUI_DragId = $LV_DragFromHere) Then
        _GUICtrlListViewCopyItems ( @GUI_DragId,@GUI_DropId, 1)
    EndIf

EndFunc
Great code!

I've been trying to get the name of the dragged item with something like

$current = _GUICtrlListViewGetHotItem ($LV_DropToHere)
or  $current = _GUICtrlListViewGetItemText($LV_DropToHere, _GUICtrlListViewGetSelectedIndices($LV_DropToHere))
    MsgBox(0, "Dropped item was" & $current)
but haven't succeeded.

What am I doing wrong?

Link to comment
Share on other sites

Well, the easiest thing to do is to edit the _GUICtrlListViewCopyItems() function in _GUIListView.au3 file so it will return the text(s). Then, you can set _GUICtrlListViewCopyItems() to a var. The var will be an array with the text of the copied item(s). Therefore, allowing you to do something like the following

For $o = 1 to Ubound($list)-1
  $current = _GUICtrlListViewGetItemText($lv, $list[$o])
  MsgBox(0, "Dropped item was",$current)
Next

But this may not be the truly easiest thing, especially considering you have to edit a standard UDF. Besides, others are probably going to yell at me for even suggesting it. I just didn't like that CopyItem doesn't return much of anything, but that's probably because of a blindness on my part. I'll keep thinking of an easier way. You also might not want to do GUISetOnEvent($GUI_EVENT_DROPPED, "Dropping") and do a GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"Dropping"). However, that means entirely changing the Dropping function.

A decision is a powerful thing
Link to comment
Share on other sites

Well, the easiest thing to do is to edit the _GUICtrlListViewCopyItems() function in _GUIListView.au3 file so it will return the text(s). Then, you can set _GUICtrlListViewCopyItems() to a var. The var will be an array with the text of the copied item(s). Therefore, allowing you to do something like the following

For $o = 1 to Ubound($list)-1
  $current = _GUICtrlListViewGetItemText($lv, $list[$o])
  MsgBox(0, "Dropped item was",$current)
Next

But this may not be the truly easiest thing, especially considering you have to edit a standard UDF. Besides, others are probably going to yell at me for even suggesting it. I just didn't like that CopyItem doesn't return much of anything, but that's probably because of a blindness on my part. I'll keep thinking of an easier way. You also might not want to do GUISetOnEvent($GUI_EVENT_DROPPED, "Dropping") and do a GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"Dropping"). However, that means entirely changing the Dropping function.

Not a good Idea to suggest changing the UDF functions, next install it would be overwritten, so the best suggestions would be to create your own functions that does what you want.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Not a good Idea to suggest changing the UDF functions, next install it would be overwritten, so the best suggestions would be to create your own functions that does what you want.

Sorry, gaFrost ;)

I'm working to supply a different method. Moreover, yeah guwguw, you could take the CopyItem function from the UDF, put it in your file, adapt it (changing it's name of course), and then you get what I was mentioning. Still this probably isn't the best idea, especially since what I'm going to show you would do what you want without having to do it.

Again, sorry for suggesting something like that. Just throwing my ideas out there.

It's kind of funny because I said someone would come along and "yell" at me for suggesting changing the UDFs :) and someone did ;) thanks Gafrost and I'll suggest different things from now on ;)

Edit:

I didn't say it was bad idea or that someone could mess things up.

Edited by JohnBailey
A decision is a powerful thing
Link to comment
Share on other sites

guwguw, try the following

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>

Opt ("GUIOnEventMode", 1)


Global $LV_DragFromHere, $LV_DropToHere
$ParentWin = GUICreate("Copy Example", 730, 447, 193, 115)
$LV_DragFromHere = GUICtrlCreateListView("Name|Number", 23, 30, 249, 399, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListViewSetColumnWidth ($LV_DragFromHere, 0, 120)
_GUICtrlListViewSetColumnWidth ($LV_DragFromHere, 1, 120)
GUICtrlSendMsg($LV_DragFromHere, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

For $x = 1 to Random(5,20,1)
    GUICtrlCreateListViewItem(_CreateRanNameish()&"|"&Random(100000,999999,1), $LV_DragFromHere)
Next

$LV_DropToHere = GUICtrlCreateListView("Name|Number", 289, 30, 249, 399, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListViewSetColumnWidth ($LV_DropToHere, 0, 120)
_GUICtrlListViewSetColumnWidth ($LV_DropToHere, 1, 120)
Global $TotalColumns = 2
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"MyHandler");<---------

$Label1 = GUICtrlCreateLabel("Drag From Here", 24, 11, 79, 17)
$Label2 = GUICtrlCreateLabel("Drop To Here", 288, 10, 69, 17)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUISetState(@SW_SHOW)

While 1
    Sleep(15)
WEnd

Func _CreateRanNameish()
    Local $Nameish = ''
    For $i = 1 to Random(4,12,1)
        $Nameish &= chr(Random(65,90,1))
    Next
    Return $Nameish
EndFunc

Func Dropping() 
    ConsoleWrite("dropping" & @CRLF)
    $Mid = GUIGetCursorInfo (WinGetHandle($ParentWin))
    Local $current = ''
    Local $selectedInd = 0
    Switch $Mid[4]
        Case $LV_DragFromHere
            If @GUI_DragId = $LV_DropToHere AND @GUI_DropId = $LV_DragFromHere Then
                Local $list = _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere, 1)
            EndIf
    
        Case $LV_DropToHere
            If @GUI_DragId = $LV_DragFromHere AND @GUI_DropId = $LV_DropToHere Then
                Local $list = _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere, 1)
            EndIf
    EndSwitch
    
    ;Local $lv = @GUI_DragId
    ;$selectedInd = _GUICtrlListViewGetSelectedIndices($lv)
    ;$current = _GUICtrlListViewGetItemText($lv, _GUICtrlListViewGetSelectedIndices($lv))
    
    MsgBox(0, "Dropped item was",$current&@LF&'at position '&$selectedInd)
    
EndFunc ;=== Props to Martin for the dropping func (http://www.autoitscript.com/forum/index.php?showtopic=51392&view=findpost&p=389002)


Func MyHandler();<---------------------Original idea from Martin
    $Mid =  GUIGetCursorInfo (WinGetHandle($ParentWin))
    If $Mid[4] = $LV_DropToHere OR $Mid[4] = $LV_DragFromHere Then
        Switch $Mid[4]
            Case $LV_DragFromHere
                Local $lvSource = $LV_DragFromHere
                Local $lvDest = $LV_DropToHere
                
            Case $LV_DropToHere
                Local $lvSource = $LV_DropToHere
                Local $lvDest = $LV_DragFromHere
        EndSwitch
        
        If _IsPressed(1) Then;if the left mouse button pressed(must be really or how did we get here)
            $noSel = _GUICtrlListViewGetSelectedCount($lvSource);the number of selected items being dragged
            
            If $noSel < 1 Then Return
            
            Local $SelItems = _GUICtrlListViewGetSelectedIndices($lvSource);the list of the items
            Local $SelItemsArray = StringSplit($SelItems,'|')
            Local $SelItemsArraySize = Ubound($SelItemsArray)-1
            Local $TextArray[$SelItemsArraySize+1]
            For $iii = 1 to $SelItemsArraySize
                $TextArray[$iii] = _GUICtrlListViewGetItemText($lvSource,$SelItemsArray[$iii])
            Next
                
            While _IsPressed(1)
                ;wait for dragging to stop
            WEnd
                
                            
            ;where is the cursor now?
            $Info =  GUIGetCursorInfo (WinGetHandle($ParentWin))
            If $Info[4] = $lvDest Then;if it's still over the listview
                _GUICtrlListViewCopyItems ($lvSource, $lvDest, 1)
                For $iii = 1 to $SelItemsArraySize
                    MsgBox(0, "Dropped item was",$TextArray[$iii]&@LF&$SelItemsArray[$iii])
                Next
            EndIf
        EndIf
        
    EndIf
EndFunc
;;;;=======Thanks Martin!===================;;;;;end


Func _CopyRight()
    _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere)
EndFunc   ;==>_CopyRight

Func _MoveRight()
    _GUICtrlListViewCopyItems ($LV_DragFromHere, $LV_DropToHere, 1)
EndFunc   ;==>_MoveRight

Func _CopyLeft()
    _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere)
EndFunc   ;==>_CopyLeft

Func _MoveLeft()
    _GUICtrlListViewCopyItems ($LV_DropToHere, $LV_DragFromHere, 1)
EndFunc   ;==>_MoveLeft


Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            _Exit()
    EndSelect
EndFunc   ;==>SpecialEvents

As you can see I'm no longer using GUISetOnEvent($GUI_EVENT_DROPPED, "Dropping") or the Dropping function. This should be self explanatory. Let me know if you need me to explain things.

A decision is a powerful thing
Link to comment
Share on other sites

Actually this might help more,

Func MyHandler();<---------------------Original idea from Martin
    $Mid =  GUIGetCursorInfo (WinGetHandle($ParentWin))
    If $Mid[4] = $LV_DropToHere OR $Mid[4] = $LV_DragFromHere Then
        Switch $Mid[4]
            Case $LV_DragFromHere
                Local $lvSource = $LV_DragFromHere
                Local $lvDest = $LV_DropToHere
                
            Case $LV_DropToHere
                Local $lvSource = $LV_DropToHere
                Local $lvDest = $LV_DragFromHere
        EndSwitch
        
        If _IsPressed(1) Then;if the left mouse button pressed(must be really or how did we get here)
            $noSel = _GUICtrlListViewGetSelectedCount($lvSource);the number of selected items being dragged
            
            If $noSel < 1 Then Return
            
            Local $SelItems = _GUICtrlListViewGetSelectedIndices($lvSource);the list of the items
            Local $SelItemsArray = StringSplit($SelItems,'|')
            Local $SelItemsArraySize = Ubound($SelItemsArray)-1
            Local $TextArray[$SelItemsArraySize+1]
            For $iii = 1 to $SelItemsArraySize
                $TextArray[$iii] = _GUICtrlListViewGetItemText($lvSource,$SelItemsArray[$iii])
            Next
                
            While _IsPressed(1)
                ;wait for dragging to stop
            WEnd
                
                            
            ;where is the cursor now?
            $Info =  GUIGetCursorInfo (WinGetHandle($ParentWin))
            If $Info[4] = $lvDest Then;if it's still over the listview
                _GUICtrlListViewCopyItems ($lvSource, $lvDest, 1)
                Local $copiedEntries = ''
                For $iii = 1 to $SelItemsArraySize
                    $copiedEntries &=$TextArray[$iii]&' at position '&$SelItemsArray[$iii]&@LF
                Next
                MsgBox(0, "Dropped item was",$copiedEntries)
            EndIf
        EndIf
        
    EndIf
EndFunc

What I changed is how it shows the items copied.

A decision is a powerful thing
Link to comment
Share on other sites

Thanks for the quick help guys!

I'm still playing around with your suggestions, but the rest of the program doesn't really care which detail I choose- as long as the items get passed on to the rest of the environment.

I was pretty much convinced that I overlooked something, but now see that only a deeper knowledge of Autoit (like yours, lol) could solve the problem satisfactorily. I had needed something similar for list boxes (but ultimately used combo boxes), and managed to figure it out by researching these forums (and the help file, naturally) ...

Thanks again

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