Solved

Drag & Drop

Posted on 1998-08-07
10
290 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now