Error when adding StructuredDocumentTag ComboBox inside table

Hi, I am having trouble getting a StructuredDocumentTag ComboBox inserted inside the cell of a table. Here is my simplified script:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.StartTable();
StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.ComboBox, MarkupLevel.Block);
sdt.ListItems.Add(new SdtListItem("Select a score", "0"));
for (double i = 1.0; i <= 5; i += .1)
{
    sdt.ListItems.Add(new SdtListItem(i.ToString(), i.ToString()));
}
builder.InsertCell();
builder.Write("Overall Score: ");
builder.InsertNode(sdt);
builder.EndRow();
builder.EndTable();
doc.Save(targetpath + filename);

I receive “Cannot insert a node of this type at this location.” error here:
InsertNode(sdt);

Any help would be greatly appreciated.

@protstein Please note that the correct approach to achieve the desired outcome is as follows:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.StartTable();
StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.ComboBox, MarkupLevel.Block);
sdt.ListItems.Add(new SdtListItem("Select a score", "0"));
for (double i = 1.0; i <= 5; i += .1)
{
    sdt.ListItems.Add(new SdtListItem(i.ToString(), i.ToString()));
}
var sdtCell = builder.InsertCell();
builder.Write("Overall Score: ");
sdtCell.AppendChild(sdt);
builder.EndRow();
builder.EndTable();

doc.Save(@"C:\\Temp\\output.docx"); 

output.docx (11.2 KB)

Thank you @eduardo.canal. This worked perfectly!

1 Like