ContentControlAfterAdd Event Fire When any Column of table is Deleted RRS feed

  • Question

  • I am working on an Add In Application,

    I have many controls inside a table so when a column is deleted, then for every control Control AfterAdd Event is fired.

    is this a known issue?

     (Note: I have created a word-Addin using VisualStudio2010)
    Thursday, February 7, 2013 2:19 PM


All replies

  • Hi kashii

    Various actions in Word can cause content controls to be re-created behind the scenes, and this can trigger events "unexpectedly". For this reason, the event provides an argument InUndoRedo. If you check the value of that argument when you perform the action that unexpectedly triggers ContentControlAfterAdd, does it return True?

    If yes, then that's how you avoid the event running your code when you don't want it to. If Not InUndoRedo Then...

    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, February 7, 2013 4:39 PM
  • Hi Cindy

    Thank you for your reply. as you mention in some cases content controls are re-created so you suggested me to check InUndoRedo argument which in my scenario give false.

    so is there any workaround for this issue.

    • Edited by kashii Friday, February 8, 2013 6:40 AM
    Friday, February 8, 2013 6:40 AM
  • Hi kashii

    This appears to be "by design", as far as it goes. See:

    From that discussion, you can see that the BeforeDelete event is triggered for all the controls before the AfterAdd event when a columns is deleted. So possibly you can use that to track whether AfterAdd is happening due to deleting columns from the table?

    The only other thing I can think of would be to re-purpose the command(s) being used to change the table structure so that you can set a Boolean that AfterAdd will test.

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, February 8, 2013 4:26 PM