I have a CustomPane with a treeView. I am trying to implement a DragDrop feature where user can drag a node from the treeview, drop it on the word document and this would create a ContentControl at the drop location.
I tried DragDrop of a string by using a TextBox as follows and it works just fine:
txtBxDummy.DoDragDrop(textToPass, DragDropEffects.Copy);
Now I want to Drag and Drop a ContentControl. Since Word Document does not expose any DragDrop events I cannot implement this feature like a common DragDrop functionality is implemented.
One thing I observed is that we can drag and drop a ContentControl from one Word document to another Word document. Since this works, I believe it might be possible to programatically drag n drop a ContentControl as well.
Any help on how this can be achieved would be greatly appreciated.
Thanks in advance
Shirish

Drag and Drop objects other than string on Word Document
GTO52
Has it in fact been determined or verified that it is or is not possible to programmatically drag and drop a ContentControl via DoDragDrop, like below
I read through the workaround described, but I am interested in whether or not the original way to try to do this is even possible.
Thanks,
Harry
Ayooya
I haven't yet found a way to implement dragDrop of ContentControls on Word document. So here is how I have implemented this feature:-
When the user drags a node from the TreeView and drop it into the word document, I create a placeholder tag ( a string like <!NODE_IDENTIFER!> ) at the drop location. Then I have a background thread running in the WordAddin which intermittently checks for the occurence of these placeholder tags and adds a ContentControl in place where it finds one. The thread keeps track of tags which have been replaced to avoid adding duplicate ContentControls.
Now my problem is that these tags can be anywhere on the document (like maybe inside a word table).
To add a content Control in place of the tag I need to know the exact range of these tags in the document. How can this be achieved
I can find the placeholder tag by doing a Wildcard search as below:
completeDocRng.Find.MatchWildcards =
true;completeDocRng.Find.Text =
@"\<\!*\!\>";completeDocRng.Find.Execute(
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);However how do I know the range for the text that was found
Best,
Shirish
kadabba
So, in order for it to work, there must be some type of wrapper around the content control that tells Word what it is and how to accept it in a drop.
My boss asks me every time I show him my task pane if I've figured out drag and drop for it yet. So I keep on searching, but haven't found anything that works yet.
Thanks,
Dennis
Stephen_Sbh
Hi Shirish
If the .Find.Execute was successful, completeDocRange should contain the found text.
Or, to put it another way, completeDocRange won't contain the original range in .Find.Execute was successful.
Handling this can be tricky if you need to continue the search after a "hit". There are a couple of possible approaches. One is to extend the Range.End to the End value of the original range (which you can store as an Int32). Another is to create a duplicate of the original range then reset after a successful find. Very roughly (pseudocode):
Word.Range completeDocRange = doc.Content;
Word.Range findRange = completeDocRange.Duplicate;
bool success = findRange.Find.Execute(//params here);
if (success) {findRange = completeDocRange.Duplicate;}//or
if (success) {findRange.End = completeDocRange.End;}
//and repeat the search
The reason you need to do this is that Word creates a deep copy if you assign one Range to another Range. Duplicate creates a shallow copy.