I've been struggling with this for quite a while
My wpf application contains a list view, populated with file-names, which are located on a server.
I'm trying to implement drag and drop functionality, so the user can drag files from my application into his/her's local computer.
In order to do this, first i'm downloading the files into a temporary location, and then calling my application's DoDragDrop() method.
The problem is that I want to perform the download process only after the DoDragDrop method is called.
I've tried every event related to drag drop methods (GiveFeedback, ItemDrag, etc...) but nothing works
so basically what I need is an event, raised after the DoDragDrop is done
any ideas?
The current scheme is to drag a file with a special suffix, and then turn on global file monitoring to obtain the drag location of the file through monitoring.
Related
I just implemented drag&drop in my application. It goes two ways:
From my app to Windows Explorer: exports files
From Windows Explorer to my app: imports files
One side effect is that I can also drag files from my application to my application (the same window), which is not intended.
Is there a elegant way to make sure, that a drag&drop operation I started won't be accepted by my application? E.g. check if the source of the drop operation != my application?
You need to register the fact that you initiated a drag from inside your application with some sort of facility or service. If you receive a drop on your application, ask the facility/service if the drag was initiated within your application. If so, discard. Reset the facility/service afterwards (in any case).
I just figured out a way to do this.
Now I set two types of data on my drag&drop data object:
The file names I want to export
A Unicode-Text object containing the name of my application
In my Drop-handler I check if a Unicode-Text object is present and if it contains my application's name. If so, I abort the drop operation.
I'm using the FileSystemWatcher to monitor a certain directory, and I need to raise one event when someone saves edits to a file, and another when they create or move a file.
Monitoring moved files works fine using a combination of the Deleted and Created events. And when someone saves edits to a file the Changed event does indeed get raised. However, when they move a file the Changed event gets raised too, and that interferes with the handling I've got for the Created and Deleted events.
So basically, I want to raise the Changed event only when the user saves edits to a file, while not when the user moves or creates a file. I tried using the ChangeType property to check if it was in fact a Changed event or a Created event, but to my surprise, the ChangeType Changed was raised for the Change event even when moving or creating a file, not the ChangeType Created (which supposedly should be one of the types).
So I don't know how to check that the Change event is actually triggered by a file edit, rather than file creation or move...
Any ideas?
This is normal behavior when you apply some of NotificationFilter such as NotifyFilter. Attributes and NotifyFilter.LastAccess, it will even notify Changed twice if both filters was applied when file move "Deleted - Created - Changed - Changed", So:
Simply don't add not relevant notify filters; If you just remove
NotifyFilter. Attributes and NotifyFilter.LastAccess
you will not receive Changed event when move file, only Deleted then Created.
If you are wishes to stick with the notify filters that you are already using, there is other hint here to allow you to generate a dirty solution, it is the fact that when the file moved, the sequence of notification will be Deleted, Created then Changed, they will be always in this order..
I am trying to implement a lazy drag and drop operation. I want to show a listview with files to my user, when the user drags a file and drops it into a folder the content should be downloaded and delivered.
I am using the IDataObject interface, but my problem is that the GetData() method is queried way too early. For instance a drag over the desktop (without any drop involved) will query the GetData() method a couple of times. And each of these calls starts the download of the file :/
Now, my question is: What's wrong here - why is the GetData() method called without any drop? Is there another way to implement lazy drag & drop operations in .net?
Maybe this could work for you...
On every occurrence of the GetData() do this:
you'll need some kind of a timer here.
if your timer is already active, kill it.
create and start a new timer. Make it 1sec or determine its duration from the experiment.
on timer event do what has to be done.
I use similar procedure on many occasions where such workaround is needed.
I think GetData is being called so that the (potential) drop target can determine whether or not it can accept the (potential) drop item(s). Have you considered using a shell extension?
I have an app with 2 DataGridView's and have implemented Drag/Drop to allow the user to move data between them. Within the context of my application dragging rows between two instances of a form isn't a meaningful action. I'm not sure how to detect it in drag enter so that I can set e.Effect to DragDropEffects.None.
If I don't do so and set it to Copy the DragDrop event fails with a cryptic exception "This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server."
While I can trap this exception to prevent a crash from happening, and abort the actual drop of data in the process it's bad practice to do so, and could be confusing to the user since the drop allowed cursor would be shown but no drop would take place.
Microsoft says that any control can accept data from a drag-and-drop operation in progress, and that you can designate a control as a drop zone by setting the AllowDrop property to true. I would think that, if you set AllowDrop to false on those controls that you do not wish to be a drop zone, you should get the desired behavior.
If you want to detect drag and drop between two instances of your program, you can set an ID in the dragging object (i.e. put a GUID in the tag of the control), and check it during the drag process to see if it matches the GUID of your currently running instance.
http://msdn.microsoft.com/en-us/library/ms973845.aspx
My C# program has a list of files that can be dragged from it and dropped into another program. My requirements are that the file be copied to a different directory first.
So, can I be notified of the drop operation so that I can only copy the file if operation succeeds? I'd rather wait till I know it needs to be copied before actually performing the copy.
Also, is it possible to know what program the drop operation is occurring in? Ideally I'd like to alter the filepath based on who or what its being dropped.
The solution to this can be in any .NET language or C/C++ with COM.
There are a few ambiguities in your question. What operation needs to be successful?
For everything you want to know about drag and drop, browse through these search results (multiple pages worth):
Raymond Chen on drag and drop
So, you intend to modify the data being dropped based on the drop target? I don't think this is possible; after all, you populate the data when the drag is initiated.