Solved

Drag & Drop

Posted on 1998-08-07
10
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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
 
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 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