-
i have 2 listbox how could i make program that when i drag and drop item from desktop list1 get the file name and list2 get complet location (ex:"c:\Program files\Internet Explorer\Iexplore.exe"). Does any one know how to do this please help me.
Thank you
-
Code:
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Data.GetFormat(15) Then
For n = 1 To Data.Files.Count
List1.AddItem Filepart(Data.Files(n))
List2.AddItem Data.Files(n)
Next n
Else
End If
End Sub
private Function Filepart(filepath)
For n = Len(filepath) To 1 Step -1
If Mid(filepath, n, 1) = "\" Then Exit For
Next n
Filepart = Mid(filepath, n + 1)
End Function
-
Hi, Kedaman,
If you look in the tips section, tip #66 shows how to drag and drop into list boxes.
http://www.vb-world.com/tips/tip66.html
-
hmm.. Kedaman's code is less complicated and works great! (i use it too!)
-
the Tip, could be useful too, (thanks Nemo) if you have controls without OLEDragDrop events ;)
-
<?>
Code:
Option Explicit
'Here 's one way that you can let users drag items from one list
'and drop them in another one.
'Create two lists (list1, list2)and a text box (text1)
Private Sub Form_Load()
' Set the visible property of text1 to false
Text1.Visible = False
'Add items to list1
List1.AddItem "This"
List1.AddItem "Example"
List1.AddItem "Comes To You"
List1.AddItem "Compliments of someone and me."
List1.AddItem "somewhere on planet earth"
List1.AddItem "Enjoy!"
'
End Sub
'In the mouseDown event of the list list1 put the following code:
Private Sub list1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, y As Single)
Dim z As Integer
z = List1.ListIndex
'do the drag
Text1.Text = List1.Text
Text1.Top = y + List1.Top
Text1.Left = X + List1.Left
Text1.Drag
'remove item from list1 and refresh listcount
List1.RemoveItem (z)
List1.Refresh
'if empty disable the box as it will result in error's on empty
If List1.ListCount = 0 Then
List1.Enabled = False
End If
'
End Sub
'In the dragDrop event of the list list2 put the following code:
Private Sub list2_DragDrop(Source As Control, X As Single, y As Single) '
List2.AddItem Text1.Text
End Sub
'Now you can drag items from list1 and drop them in list2.
-
Re: <?>
i put the code you give me above Form_OLEDragDrop but and i have 2 listbox but it's not working for me if you know why help me.
-
forgot one thing, set the form Ole_dropmode property to 1-Manual :) Should work fine.
BTW, HeSaidJoe, one thing i've been thinking about many times, why you put <?> in the post subjects? :)
-
<?>
kedeman...
the matter of the subject is the question
ie: subject = ? 'cept it's in brackets.