Dropdown list disappears on option selection

I have the below code that selects an option from a dropdown list. However, when I make the selection the dropdown list is removed and just replaced by text, the containing SDT just has a run with the selected text. Is that right?

NodeCollection sdtNodes = sdt.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (StructuredDocumentTag ddlNode in sdtNodes)
{
    if (ddlNode.SdtType == SdtType.DropDownList)
    {
        SdtListItemCollection options = ddlNode.ListItems;
        if (options.Count > 0)
        {
            foreach (SdtListItem option in options)
            {
                if (option.Value == value)
                    ddlNode.ListItems.SelectedValue = option;
            }
        }
    }
}

@markchequer I have tested the scenario and Aspose.Words behaves correctly. MS Word shows dropdown with the selected item text. However you are right, the selected item text is represented as a Run with the selected item:

This is the expected behavior. The same occurs when an item is selected in MS Word. Here is how such SDT looks internally:

<w:sdt>
	<w:sdtPr>
		<w:id w:val="-654842769"/>
		<w:placeholder>
			<w:docPart w:val="DefaultPlaceholder_-1854013438"/>
		</w:placeholder>
		<w:dropDownList>
			<w:listItem w:value="Choose an item."/>
			<w:listItem w:displayText="test1" w:value="test1"/>
			<w:listItem w:displayText="test2" w:value="test2"/>
			<w:listItem w:displayText="test3" w:value="test3"/>
		</w:dropDownList>
	</w:sdtPr>
	<w:sdtContent>
		<w:p w14:paraId="1B067FEF" w14:textId="5B574D16" w:rsidR="002B2CA3" w:rsidRDefault="002B2CA3">
			<w:r>
				<w:t>test3</w:t>
			</w:r>
		</w:p>
	</w:sdtContent>
</w:sdt>

Thank you for confirming.

1 Like