none
Editable group content control RRS feed

  • Question

  • Hi all,

    I'm programmatically inserting group content controls to keep track of a documents nested structure. Group content controls don't allow editing text inside it except when it's inside a child content control (for example a text or richtext content control that is a child of the group content control).

    In this solution I cannot use content controls for the child content, because of Word's limitations when it comes to the total number of content controls in a document. Hence I'm using regular paragraphs for the content itself inside the group content controls. Is it possible to allow the regular paragraph text inside the group content control to be editable, without having to switch to forms design mode (ToggleFormsDesign())?

    I managed to create a document with the OpenXML SDK where I simply removed the <w:group/> element from the <w:sdtPr> element. In that case all content is editable inside the group content control, but I don't have access to the OpenXML markup of the document itself using VSTO.

    Is there any property in the Word object model that I can use to get rid of the <w:group/> element, or does it always render this for a group content control?

    Hope anyone can help. Thanks in advance.

    Ruben.

    Edit: here's the source code I use to insert the group content controls:

    curRange.Start = start; curRange.Select(); var attrs = node.Attributes; var cc = ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlGroup, curRange); cc.Temporary = true; cc.LockContentControl = false; var lbl = attrs.GetNamedItem("label"); cc.Tag = lbl.Value; var title = attrs.GetNamedItem("title"); cc.Title = title.Value;


    • Edited by Ruben E Wednesday, April 18, 2012 10:26 PM Added source snippet
    Wednesday, April 18, 2012 10:20 PM

Answers

  • Hi again,

    Sometimes things are easier than they look at first sight. I figured out that, besides group content controls, richtext content controls are also able to contain child elements, including other content controls. So the only thing I had to change in the above code snippet was the type parameter in this line:

    var cc = ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlGroup, curRange);

    into:

    var cc = ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlRichText, curRange);

    Hope this may help someone else in the future.

    Ruben.

    Wednesday, April 18, 2012 11:05 PM

All replies

  • Hi again,

    Sometimes things are easier than they look at first sight. I figured out that, besides group content controls, richtext content controls are also able to contain child elements, including other content controls. So the only thing I had to change in the above code snippet was the type parameter in this line:

    var cc = ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlGroup, curRange);

    into:

    var cc = ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlRichText, curRange);

    Hope this may help someone else in the future.

    Ruben.

    Wednesday, April 18, 2012 11:05 PM
  • Hi Ruben,

    I'm glad to hear you have solved it via yourself. Thanks for sharing your experience here, it's very beneficial for other community members who have similar problem to see how you solved it.

    Have a good day,

    Tom


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

    Monday, April 23, 2012 8:31 AM
    Moderator