[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Drag & Drop

I'm having a hard time getting drag and drop to work.  I want to be able to drag from ANY program and drop into a list box.  The main problem I'm having is knowing what gets put in the OLEDragDrop, by putting in the wrong info I was able to get the wrong info added to list box but not the text I dragged.  Any ideas?
0
dokken
Asked:
dokken
  • 5
  • 4
1 Solution
 
anthonycCommented:
can ya show the code you used?  
0
 
dokkenAuthor Commented:
Well, the only code I was adding was:

lstbox.additem (then I tried a million different things here)

I never tried to add Drag and Drop to a program before.
In the properties for the list box I set:
OLEDragMode = Automatic
OLEDragDrop = Manual  (there were only two choices that and none)

When I drag something over the listbox I get the drop mouse pointer, but I just don't know what to put under the event.
0
 
BlackAndWhiteCommented:
When something is dragged over the control, the dragover event gets fired, and when something is dropped in the control, dragdrop fires.  However you application has to determine what was dropped...or atleast process only if the dropped object was of a certain type.  For example in the drop event of my listbox, if I expected only files from Windows Explorer, I would say...    

     Dim i As Integer
   
    If Data.GetFormat(vbCFFiles) = True Then
        For i = 1 To Data.Files.Count
            ListBox1.Add Data.Files.Item(i)
        Next
    End If

.You have to check what gets dropped and handle accordingly..


Feel free to ask if this doesnt answer your question..
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dokkenAuthor Commented:
It's close, I want to just add a line of text... not a file.
0
 
dokkenAuthor Commented:
Adjusted points to 50
0
 
BlackAndWhiteCommented:
   If Data.GetFormat(vbCFFiles) = True Then
        For i = 1 To Data.Files.Count
            '######Instead on this
            'ListBox1.Add Data.Files.Item(i)
            '######Add your Line of text..
            ListBox1.Add "My Line Of Text" & i
        Next
    End If

You can also have it outside the loop if you want to add only one line for the drop operation involvind all files...and even take off the for loop all together...
0
 
dokkenAuthor Commented:
BlackAndWhite,

Just tried your suggestion but it doesn't work.  The information I'm trying to add is just a normal line of text.  Like just draging a word or something from IE or any other application.  Maybe this is more trouble then it's worth. I haven't been able to find the answer to this anywhere.  I just thought it would be cool to add to the program.
0
 
BlackAndWhiteCommented:
Change the type of Getformat to vbCFText
Try this out..

Private Sub ListView1_OLEDragDrop(Data As ComctlLib.DataObject,  Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim i As Integer
   
    If Data.GetFormat(vbCFText) = True Then
        MsgBox Data.GetData(vbCFText)
    End If
End Sub



0
 
dokkenAuthor Commented:
That did it! I after I tested it, I changed to add it to the listbox and it worked perfectly.  I'll give you an 'A'
0
 
BlackAndWhiteCommented:
Thank You for the A.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now