Solved

Drag & Drop

Posted on 1998-08-07
10
288 Views
Last Modified: 2010-04-30
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
Comment
Question by:dokken
  • 5
  • 4
10 Comments
 
LVL 6

Expert Comment

by:anthonyc
ID: 1468245
can ya show the code you used?  
0
 

Author Comment

by:dokken
ID: 1468246
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
 
LVL 1

Expert Comment

by:BlackAndWhite
ID: 1468247
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
 

Author Comment

by:dokken
ID: 1468248
It's close, I want to just add a line of text... not a file.
0
 

Author Comment

by:dokken
ID: 1468249
Adjusted points to 50
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Expert Comment

by:BlackAndWhite
ID: 1468250
   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
 

Author Comment

by:dokken
ID: 1468251
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
 
LVL 1

Accepted Solution

by:
BlackAndWhite earned 50 total points
ID: 1468252
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
 

Author Comment

by:dokken
ID: 1468253
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
 
LVL 1

Expert Comment

by:BlackAndWhite
ID: 1468254
Thank You for the A.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now