Update or refresh Word ContentControls

混江龙づ霸主 提交于 2019-12-13 07:22:28

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/38986922/update-or-refresh-word-contentcontrols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!