Solved

Dragacceptfiles on a form with multiple controls....

Posted on 2006-10-31
11
355 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

778 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