Hexie
Hexie

Reputation: 4221

Update or refresh Word ContentControls

I have a scenario whereby I need to (programmatically) add ContextControls to a Word table.

My example is when a user adds a ContentControl to a table (first cell) then adds a repeating ContentControl to that row - this is perfect!

If the user then goes to cell 2 of a 2 cell table (to keep things simple) and adds another ContentControl - keeping in mind this row is already a repeating ContentControl and now just has an additional ContentControl added, the data does not repeat.

If I go into my Word ribbon - Developer, then flick design on and off, the data all appears fine again (almost like the repeating ContentControl was updated / refreshed). I'm wondering - is there a way to do this through code?

Something like repeating ContentControl.Update / Refresh / Reload (none of those exist).

Right now - I'll even accept if I can do this through the Word application itself, but I will be converting this to code.

enter image description here

Upvotes: 1

Views: 1101

Answers (1)

Hexie
Hexie

Reputation: 4221

For anyone needing the answer to this:

After 3 days, I've decided that the best way to accomplish this task, is by calling the .ToggleFormsDesign method twice.

This will basically "refresh / update" the binding on the repeating ContentControl

        With ActiveDocument
            .ToggleFormsDesign
            .ToggleFormsDesign
        End With

Calling this method back to back, will have no UI / visual impact (i.e. the user will not notice anything).

MSDN Link to the Method

Upvotes: 1

Related Questions