none
Word - VSTO Add-in - disable drag drop of content controls RRS feed

  • Question

  • I have an existing VSTO based Word add-in that runs in Word 2007 and Word 2010. 

    First some relevant info:
    1) We allow users to create Rich Text Content Controls via a new ribbon button that our add-in presents

    2) We display the content controls, in the order they appear on the Word surface, in a task pane

    3) We allow users to move content controls around by dragging and dropping the representations of those content controls in our task pane

    4) To block users from accidentally deleting content controls we programatically set each content control to not be deletable

    5) We store data about the content controls (contents, location, etc...) in a db on a server.

    Now for the issue:
    Content Controls inherently have a small "tab" that appears on the Word surface.  Users can grag this tab and drag content controls to new locations on the Word surface.   Word's default behavior in this case is to perform a "cut & paste".  However, if a content control is not allowed to be deleted (as ours are), Word tries to be "helpful" and switches from "cut & paste" to "copy & paste".  So now when a user drags and drops via the "tab" on the content control, they make duplicates.  This causes us problems.  The best solution I have found so far is to hook the ContentControl_Add event and delete any content control that is not explicitely added via our new ribbon button.  This solution is "hacky" at best, and flat doesn't work at worse.

    I need to do one of the following (in order of preference)
    1) Do not allow the user to do drag & drop using the tab of the content control.  i,e, detect that that is what they are doing and cancel it

    2) Detect the drop and stop that from happening at all

    3) Hide the tab that appears on the content control.  If there is no tab, then users can't grab it to move it around.

    As far as I have been able to determine, there is no method/event/property in Word or VSTO that allows me to disable drag/drop, detect drop, or hide the tab.

    I have looked into hooking windows events that occur during the drag drop but did not see any messages relevent to the content control come through.

    Is there ANY way that I can accomplish my goal?  (disable drap/drop of content controls, detect drop of content control, hide the content control tab)?

    Thank you very much

    Kelly

    Tuesday, May 1, 2012 10:59 PM

Answers

  • Hi Kelly,

    ContentControl.LockContentControl can prevent contentcontrol from moving, but could not prevent from "Copy and Paste" as you noticed.

    I'm afraid there's no better idea besides the current workaround.  However, it could be over kill, you may compare the contents of the controls and delete a control if content is same as existing control.

    best regards,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Thursday, May 3, 2012 1:34 PM
    Moderator

All replies

  • Hi Kelly,

    Thanks for posting in the MSDN Forum.

    I will involve some experts into this thread to see whether they can help you. There might be some time delay, appreciate for you patience.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, May 3, 2012 5:28 AM
    Moderator
  • Hi Kelly,

    ContentControl.LockContentControl can prevent contentcontrol from moving, but could not prevent from "Copy and Paste" as you noticed.

    I'm afraid there's no better idea besides the current workaround.  However, it could be over kill, you may compare the contents of the controls and delete a control if content is same as existing control.

    best regards,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Thursday, May 3, 2012 1:34 PM
    Moderator