How to update font settings of combo text?

Hello,

I am creating a Combo in a word and i try to set some specific font settings on the selected text but it does not work.
Perhaps i’am not doing it in a wrong way.

Here is the source code :

StructuredDocumentTag sdt = new StructuredDocumentTag(document, SdtType.COMBO_BOX, MarkupLevel.INLINE);
SdtListItem sli1 = new SdtListItem("value1","value1");
SdtListItem sli2 = new SdtListItem("value2","value2");
SdtListItem sli3 = new SdtListItem("value3","value3");
sdt.getListItems().add(sli1);
sdt.getListItems().add(sli2);
sdt.getListItems().add(sli3);
sdt.getListItems().setSelectedValue(sli1);
Run sdtRun = (Run)sdt.getChild(NodeType.RUN, 0, false);
sdtRun.getFont().setStrikeThrough(true);
sdtRun.getFont().setBold(true);
sdtRun.getFont().setItalic(true);

Is this correct to set font settings on selected text of a combo ?

Hi Jean,

Thanks for your inquiry. Please use StructuredDocumentTag.ContentsFont property to set the font formatting that will be applied to text entered into SDT. See the highlighted code snippet below. Please let us know if you have any more queries.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.COMBO_BOX, MarkupLevel.INLINE);
SdtListItem sli1 = new SdtListItem("value1","value1");
SdtListItem sli2 = new SdtListItem("value2","value2");
SdtListItem sli3 = new SdtListItem("value3","value3");
sdt.getListItems().add(sli1);
sdt.getListItems().add(sli2);
sdt.getListItems().add(sli3);
sdt.getListItems().setSelectedValue(sli1);
sdt.getContentsFont().setStrikeThrough(true);
sdt.getContentsFont().setBold(true);
sdt.getContentsFont().setItalic(true);
builder.insertNode(sdt);
doc.save(MyDir + "Out.docx");

Hello,

Thanks a lot.
It’s working fine now.

Have a nice day

Best regards,

Hi Jean,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.