I would like to get the selected value from a StdContentComboBox, this is a Content control placed in a docx document. I need to get the selected value in .NET, Thanks
Asked
Active
Viewed 234 times
1 Answers
0
Try this:
using (WordprocessingDocument myDoc = WordprocessingDocument.Open("yourDocPath", true))
{
var sdtElements = myDoc.MainDocumentPart.Document.Body.Descendants<SdtElement>();
var contentControlsWithComboBoxes = sdtElements.Where(x => x.SdtProperties.Elements<SdtContentComboBox>().Any());
var contentRuns =
contentControlsWithComboBoxes.Select(x => x.Elements<SdtContentRun>());
var selectedValues = contentRuns.Select(x => x.FirstOrDefault().InnerText); // Your selected combobox values
}

Flowerking
- 2,551
- 1
- 20
- 30
-
That doesn't seem to work, I have found however, that getting the inner text for the associated SdtBlock of the SdtContentComboBox gives you the text for the selected item. – Rafael Feb 19 '13 at 17:05