Results 1 to 9 of 9

Thread: Listbox drag and drop

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    77

    Unhappy

    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

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    New Member
    Join Date
    Nov 2000
    Location
    Montreal, Canada
    Posts
    14

    Talking

    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
    File not found!
    Abort, Retry, Get a Beer...

    L8r

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    hmm.. Kedaman's code is less complicated and works great! (i use it too!)
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    the Tip, could be useful too, (thanks Nemo) if you have controls without OLEDragDrop events
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    77

    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.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    kedeman...

    the matter of the subject is the question

    ie: subject = ? 'cept it's in brackets.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width