But the above code inserts the checkbox before the SDT and not within it. If I try moving the builder to the LastChild of the node and then try to insert the checkbox, it throws an exception ().
I’m attaching the source and destination document for your reference.
Thanks for your inquiry. Your target document contains the content control of type Checkbox. You can insert it into Document using following code example. If you want to insert checkbox (legacy form control) inside StructuredDocumentTag (content control), please move the cursor to the first node of it and insert checkbox (legacy form control).
Please let us know if you have any more queries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
Paragraph para = builder.InsertParagraph();
StructuredDocumentTag checkbox = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
para.AppendChild(checkbox);
doc.Save(MyDir + "Out v17.2.0.docx");
Thanks for your inquiry. In this case, you need to replace the content control of type checkbox with the existing content control. Please check following code example. Hope this helps you.
Since my new question is related to this thread, I’m attaching the new question here.
The only way to add a checkbox to the document is using the “Checkbox SDT”. Now, what if I want to change the font family, size of the checkbox attached and want to make it bold? Is there a way to do that? Because if I try to do the same manually ( viz. selecting the checkbox in the doc and increase the size, it works ). But I’m not able to do the same from the code behind.
Thanks for the solution. I tried it but it doesn’t seem to work I guess. But when I open the output document, put the design mode off and then try to uncheck or check the checkbox, then it shows the properties that I set.
We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-15602. Your thread has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.