Solved

Dragacceptfiles on a form with multiple controls....

Posted on 2006-10-31
11
359 Views
Last Modified: 2008-02-01
i have a form with multiple textboxes, listboxes and command buttons. now the requirement is if i drag and drop file(s) from 'windows explorer', how can i get the OleDragDrop event of the form triggerred regardless of where the users 'drops' the files [i.e regardless of on which control the user releases the mouse]
0
Comment
Question by:expertfan
[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
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17842120
For the controls oledragdrop event, just call the form oledragdrop event

Private Sub text_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_OLEDragDrop data, effect, button, shift, x, y
End Sub


0
 

Author Comment

by:expertfan
ID: 17842139
no i don't want to code in every controls oledgradrop event, i am looking for a generic solution so that it can handled at a common place like 'forms oledragdrop event'
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842732
This is an unfortunate limitation of VB6...there isn't any way to make global event handlers (other than control arrays consisting of the same type of control) except by adding code all over the place.

If you want dynamic event handling then move on up to VB.Net....
0
Independent Software Vendors: 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!

 

Author Comment

by:expertfan
ID: 17842755
really???

can't we handle the oledragdrop on a form if the drop happens on the controls on the form.....i hope someone should have a workaround.
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17842791
What is wrong with the sample I gave you? It is not adding any work to you other then copy and paste this "Form_OLEDragDrop data, effect, button, shift, x, y" for all controls. If you have over 100 hundred controls, this will take few minutes. If you still don't want to do this then move up to VB.Net as idle mind suggested.  

If you drop on a text box, the form oledragdrop event is not fired so no, it will not work. that is why I suggested to call the routine from each control.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842793
"can't we handle the oledragdrop on a form if the drop happens on the controls on the form"

Yes you can...

lunchbyte gave you that solution already:

    Private Sub text_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
        Form_OLEDragDrop data, effect, button, shift, x, y
    End Sub

The drop above is occuring in the "text" control and he is then passing that info along to the forms OLEDragDrop "event handler" sub.

Of course you have to do this for every control that you want "passed on"!

There may be a solution using subclassing...would have to go searching...
0
 

Author Comment

by:expertfan
ID: 17842812
yes my current code is exactly what you said, every control i have the oledragdrop event coded :)

i am looking for a better solution.
0
 
LVL 2

Accepted Solution

by:
quarkphoton earned 500 total points
ID: 17842886
this can be done using subclassing....

http://www.vbcodemagician.dk/resources/dragcomponent.htm
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842904
Found a subclassing example by wpsjr1 here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_11678998.html#4945622

A quick test allowed the drop to be made on any control on the form.

I just changed the Forms code to hook the form instead of a flexgrid:

Option Explicit

Private Sub Form_Load()
  DragAcceptFiles Me.hwnd, 1   ' begin accepting
  Hook Me.hwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
  UnHook Me.hwnd
  DragAcceptFiles Me.hwnd, 0   ' stop accepting
End Sub
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 17848628
If you have multiple dropped files you can use this routine, same as Idle Minds except that example will only throw out the first dropped file in the buffer.

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22010741.html
0
 

Author Comment

by:expertfan
ID: 17878680
thanks quarkphoton!!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 83
Sending a email via excel using vba 6 109
vbModal 12 66
Set WorkSheet  not Working 9 50
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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

740 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