Implement lazy drag & drop - c#

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?

Related

Perform dragdrop implementation after DoDragDrop method is called?WPF

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.

DevExpress Spell Checker: Is there an easy (built-in) way to propagate spell checker options updates?

I have an application that contains multiple MemoEdit controls containing DevExpress spell checkers. When a user updates the Options (through a MemoEdit's context menu), we are saving those options to our db. Is there any built-in way to broadcast those new options to all spell checkers in the application? It's probably worth noting that some of the MemoEdits are used in Interop controls in the VB6 "part" of our application.
Right now I'm using events, but things aren't working out as well as I'd hoped and before I get too deeply into rolling my own fix I figured I'd ask the SO folks.
Thanks in advance for any tips.
My tech lead and I just acquired dev express subscription for a win forms application we are building and we are using the spellchecker and saving the options to our sql server ce table. We have multiple forms with one spellchecker each tied to one memo edit control per form.
I programmed a single reusable function named “GetSpellCheckerOptions” which returns type “DevExpress.ExtraSpellChecker.OptionsSpelling” that loads the six options from the spell check options dialog form from our sql server ce table. This function is invoked in a form’s constructor where the form has the spellchecker component associated to it and this can be any form in our application. It is built around an “on-demand” basis as opposed to loading it in memory and keeping it around for the lifetime of the application because the notes or comments being written by our users are on forms that load, fill it out and close.
You can use the event called OptionsChanged which is a member of the type “DevExpress.ExtraSpellChecker.OptionsSpelling”. You will have hook up the event in runtime using a subroutine you write like this for example:
jobsSpellChecker.OptionsSpelling.OptionChanged += new EventHandler(this.jobsSpellChecker_OptionChanged);
When a user changes an option on the spell check options dialog this event will fire, however there are some gotchas to be aware of. When the event fires you will not know which option fired the event because the Event Argument does not provide that information. So I save as a whole save regardless of which options were changed. The save occurs after the OK button is clicked as opposed per option being changed. The biggest gotcha is that this event fires three times. Two of those three times is from something totally unrelated to changing an option. So to control the two unneed event fires you need an if statement evaluating the options form dialog result, like this for example,
if(jobsSpellChecker.FormsManager.OptionsForm.DialogResult == System.Windows.Forms.DialogResult.OK)
This will protect your save code from being executed needlessly. In addition without the “if” statement the control has a nasty way of remembering previous state of what the options were before you changed them and during those unneeded two of three event fires, it changes your options setting from the new desired settings back to previous state or settings. Very annoying and it has taken the whole day to get past these obstacles and more experimenting with these controls. Hopefully this information can offer you or someone else a value that will save time, avoid potential frustration and endless browsing product support pages.

C# Event getting Triggered from same Event to Create it

I am using a Input system which manages input from all controllers, keyboard, etc. If you would like to check it out visit: http://mquandt.com/blog/2010/01/xna-input-manager-sample/
I have modified that input manager to have a queue system so that (in theory) would stop the event triggering to boil over when in the middle of a update.
Here is a bare bones example of my issue (This uses the XNA 4.0 framework):
http://www.mediafire.com/?9ynabpvls19u0sq
To explain my problem better if you don't want to download:
An input bind is created. After trigger the bind is deleted and a new one is added. But the same button press to delete and add the new one triggers the one that was added. This cycle continues with any number of binds. One->Three
What should happen is that on button press, old one is deleted and new one is added. Then after another button press add, delete, etc. One->Two->Three
I have figured out that if I add a breakpoint or a thread sleep of 100ms on the ActionDown of InputAction then it works correctly. I guess something is going wrong because it is going too fast but a thread sleep is not a solution.
Make DeActivate method where you can UnBind or destroy or disable your action.

What't the best way to automate a WinForms app with command line arguments?

I have written a small WinForms tool with some textboxes, radiobuttons, checkboxes and a start button. So you enter your input, click on start and there is goes.
Now I want to implement to let the user do some batch processing by allowing command line arguments be passed over.
In the past I would have done it this way:
parse the command line arguments and fill the textboxes, radiobuttons and checkboxes in the Windows.OnLoad event
Enable a timer in Form.onLoad event to fire after maybe 100ms
When the timer fires, disable the timer and let it click on the GUI's start button.
This works, but I'd like to know about more elegant ways of doing this.
How would you solve this?
EDIT:
I want to always show the form as it has a Backgroundworker with a progress bar.
It sounds like your function that does the processing reads from the form directly. It is significantly cleaner to have that function accept all the data as arguments and then when submitting your form, have the data harvested and then passed to the function.
Working this way will enable you to call the function from whatever portion of the program you wish, such as when parsing the arguments passed to the program.
No need for timers, and no need involve the UI at all for the batch. As Treb mentioned, for batch processing, you may choose to never even show the form (or even UI at all)
If you use UI patterns such as MVP and MVC you can externalize the batch process logic to non UI based classes. If you imagine your console as another UI type then you can build that on top of your existing business logic.
Why is your UI mixed up with your business ? You should have a business part, and a UI part. The UI and the CLI should just act as interfaces to your business.
That is the cleanest way to go.
And concerning your progress bar, just think of a system were you can read a value in % from your business, which would indicate the percentage of work finished.
Not all that hard

Notification of drop in drag-drop in Windows

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.

Categories