I am trying to setup a system to drag and drop multiple files (or all files within a folder) from one Listbox to another.
My code works on OS X with no problem, but when run in Windows, it does not.
Here is what I have under DragRow on one ListBox:
dim nRows, i as integer
nRows=me.ListCount-1
for i=0 to nRows
if me.Selected(i) then
Drag.AddItem(0,0,20,4)
dim f as FolderItem
Dim vol As New FolderItem
f = vol.GetRelative(me.RowTag(i))
Drag.Text=f.NativePath
End if
Next
Return True
Here is what I have under DropObject on another listbox:
dim oFolderList() as FolderItem
If obj.TextAvailable Then
do
dim f as FolderItem = GetFolderItem(obj.Text,FolderItem.PathTypeNative)
if f.Directory then
oFolderList.Append(f)
while (UBound(oFolderList) >= 0)
for x as integer = 1 to oFolderList(0).count
dim f2 as FolderItem = oFolderList(0).TrueItem(x)
if f2 = nil then Continue
if f2.Exists = False then Continue
if f2.Name = "." or f2.Name = ".." then Continue
if f2.Directory then
oFolderList.Append(f2)
else
dim txt as String = f2.NativePath
if f2.NativePath.Lowercase.InStr(".dwg") <> 0 and f2.NativePath.Lowercase.InStr("bei_") = 0 then
Me.AddRow(f2.NativePath)
end if
end if
next x
oFolderList.Remove(0)
wend
else
Me.AddRow(obj.Text)
end if
loop until not obj.NextItem
End If
Anyone have any ideas why this would work on a Mac and not on Windows?
I have not tried this on MAC, but…
- I persume you have set up…
FirstListbox.EnableDrag = true
SecondListbox.AcceptTextDrop
- In the dragrow event, there is already an exsiting dragitem, so you do not need the drag.additem line for the first item.
In my test here if you do something like…
dim donefirst as boolean = false
dim nRows, i as integer
nRows=me.ListCount-1
for i=0 to nRows
if me.Selected(i) then
if donefirst then Drag.AddItem(0,0,20,4)
donefirst = true
...
...
then it works, if you don’t it fails.
Yes, I have the properties setup properly, but I even went back and checked.
When I do that, it only adds the first item, then stops working and it still doesn’t work on Windows, only on a Mac.
On windows, in my test prog, which has 2 single column listboxes…
Window Open event…
[code]dim atrow as integer
dim myfile as string
self.ListboxA.SelectionType = 1
myfile = “c:\temp\test1.tif”
self.ListboxA.AddRow myfile
atrow = self.ListboxA.LastIndex
self.ListboxA.RowTag(atrow) = myfile
myfile = “c:\temp\test2.tif”
self.ListboxA.AddRow myfile
atrow = self.ListboxA.LastIndex
self.ListboxA.RowTag(atrow) = myfile
self.ListboxB.AcceptTextDrop
self.ListboxA.EnableDrag = true[/code]
It works if I have
Drag.Text = me.RowTag(i)
to set the text in the DragRow event, but it fails to set f
if I use your,
f = vol.GetRelative(me.RowTag(i))
I’ve never used GetRelative
so I don’t know if this is where your problem lies -
but I don’t know what you have in the rowtag.
But the drag-drop of text works for both single and multile rows on Win.8.1 here ( Xojo 2013 r4.1 )
Hope this helps
Thank you, that got me on the right track at least. I am getting files (including paths) from the folderbrowser example, so I did need the getrelative.
What I had to was this:
[quote] dim DoneFirst as Boolean = False
dim nRows, i as integer
nRows=me.ListCount-1
for i=0 to nRows
if me.Selected(i) then
dim f as FolderItem
Dim vol As New FolderItem
f = vol.GetRelative(me.RowTag(i))
dim txt as String = f.NativePath
if donefirst then Drag.AddItem(0,0,20,4)
donefirst = true
drag.Text = txt
End if
Next
Return True[/quote]
So, a big thank you for your help, it definitely pointed me in the right direction.