Drag & Drop only drops sometimes in Word

D

David Thielen

Hello;

I have a C# Word Add-In (not VSTO) and I am calling DoDragDrop and passing
it an IDataObject implementing class.

About 2/3 of the time, I cannot drop this object into Word - I never get the
drop cursor. Here's what is happening:

It calls:
public string[] GetFormats(bool autoConvert)
{
return new string[] {DataFormats.Rtf} ;
}

Then it calls:
public bool GetDataPresent(string format, bool autoConvert)
{
return format == DataFormats.Rtf;
}

The thing is - when it's not working it calls this asking for a number of
formats: FileDrop, Woozle, Office Drawing Drag-Drop Format, Office Drawing
Shape FOrmat, PNG+Office Art, GIF+Office Art, JFIF+Office Art, MSClipGallery,
and HTML Format. But not Rich Text Format.

Then the next time it asks for RTF. Why?????
 
D

David Thielen

This is hard to figure out exactly what is going on because I have to record
it and then break as it is based on the mouse being down so I can't just stop
in the debugger.

Anyways, it looks like many times it calls GetDataPresent() on FileDrop and
that's it.


???
 
P

Peter Huang [MSFT]

Hi David,

Do you drag drop from the winform in the addin to the Winword windows?
If so, did the code below work for you?
private void richTextBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
this.richTextBox1.LoadFile(@"C:\test.rtf");//load rtf data
DataObject myDataObject = new DataObject();
myDataObject.SetData(DataFormats.Rtf, false,this.richTextBox1.Rtf);

this.richTextBox1.DoDragDrop(myDataObject,DragDropEffects.Copy);//drag/drop
to winword windows
}

If I have any misunderstanding, can you show some code for me to understand
your scenario more correctly?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

I got the problem not only with your example, but with a simple text string
which renders to most any format. Here is my log when I used my IDataObject
object as it shows the call in to the object.

Note that the 1st and 4th time worked. But the 2nd and 3rd time while it
called GetDataPresent() for FileDrop - it then gave up.

11:52:7.633 MouseDown
11:52:7.648 GetFormats(bool autoConvert)
11:52:8.69 GetDataPresent(FileDrop, bool autoConvert)
11:52:8.350 GetDataPresent(Woozle, bool autoConvert)
11:52:8.350 GetDataPresent(Office Drawing Drag-Drop Format, bool autoConvert)
11:52:8.350 GetDataPresent(Office Drawing Shape Format, bool autoConvert)
11:52:8.350 GetDataPresent(PNG+Office Art, bool autoConvert)
11:52:8.350 GetDataPresent(GIF+Office Art, bool autoConvert)
11:52:8.350 GetDataPresent(JFIF+Office Art, bool autoConvert)
11:52:8.350 GetDataPresent(MSClipGallery, bool autoConvert)
11:52:8.350 GetDataPresent(HTML Format, bool autoConvert)
11:52:8.350 GetDataPresent(Rich Text Format, bool autoConvert)
11:52:9.222 GetDataPresent(Object Descriptor, bool autoConvert)
11:52:9.222 GetDataPresent(Woozle, bool autoConvert)
11:52:9.222 GetDataPresent(Office Drawing Drag-Drop Format, bool autoConvert)
11:52:9.222 GetDataPresent(Office Drawing Shape Format, bool autoConvert)
11:52:9.222 GetDataPresent(PNG+Office Art, bool autoConvert)
11:52:9.222 GetDataPresent(GIF+Office Art, bool autoConvert)
11:52:9.222 GetDataPresent(JFIF+Office Art, bool autoConvert)
11:52:9.222 GetDataPresent(MSClipGallery, bool autoConvert)
11:52:9.222 GetDataPresent(HTML Format, bool autoConvert)
11:52:9.222 GetDataPresent(Rich Text Format, bool autoConvert)
11:52:9.222 GetDataPresent(Rich Text Format, bool autoConvert)
11:52:9.222 GetData(Rich Text Format, bool autoConvert)
11:52:9.222 Pasted
11:52:11.950 MouseDown
11:52:11.950 GetFormats(bool autoConvert)
11:52:11.950 GetDataPresent(FileDrop, bool autoConvert)
11:52:15.301 MouseDown
11:52:15.301 GetFormats(bool autoConvert)
11:52:15.395 GetDataPresent(FileDrop, bool autoConvert)
11:52:17.982 MouseDown
11:52:17.982 GetFormats(bool autoConvert)
11:52:18.216 GetDataPresent(FileDrop, bool autoConvert)
11:52:18.481 GetDataPresent(Woozle, bool autoConvert)
11:52:18.481 GetDataPresent(Office Drawing Drag-Drop Format, bool autoConvert)
11:52:18.481 GetDataPresent(Office Drawing Shape Format, bool autoConvert)
11:52:18.481 GetDataPresent(PNG+Office Art, bool autoConvert)
11:52:18.481 GetDataPresent(GIF+Office Art, bool autoConvert)
11:52:18.481 GetDataPresent(JFIF+Office Art, bool autoConvert)
11:52:18.481 GetDataPresent(MSClipGallery, bool autoConvert)
11:52:18.481 GetDataPresent(HTML Format, bool autoConvert)
11:52:18.481 GetDataPresent(Rich Text Format, bool autoConvert)
11:52:19.104 GetDataPresent(Object Descriptor, bool autoConvert)
11:52:19.104 GetDataPresent(Woozle, bool autoConvert)
11:52:19.104 GetDataPresent(Office Drawing Drag-Drop Format, bool autoConvert)
11:52:19.104 GetDataPresent(Office Drawing Shape Format, bool autoConvert)
11:52:19.104 GetDataPresent(PNG+Office Art, bool autoConvert)
11:52:19.104 GetDataPresent(GIF+Office Art, bool autoConvert)
11:52:19.104 GetDataPresent(JFIF+Office Art, bool autoConvert)
11:52:19.104 GetDataPresent(MSClipGallery, bool autoConvert)
11:52:19.104 GetDataPresent(HTML Format, bool autoConvert)
11:52:19.104 GetDataPresent(Rich Text Format, bool autoConvert)
11:52:19.104 GetDataPresent(Rich Text Format, bool autoConvert)
11:52:19.104 GetData(Rich Text Format, bool autoConvert)
11:52:19.104 Pasted
 
P

Peter Huang [MSFT]

Hi David,

Have you tried exact the same code as I provide?
To isolate the problem, I think you may try to use the default IDataObject
firstly.

Also I think it is importance for us to reproduce the problem at our side.
So could you provide a simple reproduce sample together with the detailed
reproduce steps to us to further troubleshooting.

Thanks!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Yes, I had the problem with your code and with the case of just passing a
string.

I listed details from my example as it provided more information.

I've also noticed the same thing just dragging from one instance of Word to
another. No Add-ins, nothing special, just select text in one, drag to
second. ABout 1 time out of 5 it won't accept the dragged text.
 
P

Peter Huang [MSFT]

Hi

Based on my understanding, you mean even if there is no any addin or macro,
we just open two word documents, and drag string from document A to doument
B.
You will also failed about 1/5.
Based on my test, I continuously drag 10 strings from document A to
document B without failure.
So I guess there may some error inside the word itself.

If so I think you may try to reinstall the word application.

If I have any misunderstanding, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Yes. I just tried again - same thing about 1/5 of the time.

When it wouldn't drop in Word I then dragged over my text editor and it
would not drop there either.

As you said - probably some error inside Word but definitely not an error in
my Add-in.
 
P

Peter Huang [MSFT]

Hi

Thanks for your understanding.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top