I want to change of a ContentControl using Word.Interop. It works with a ContentControl of Type Text. But it fails with a ContentControl of type wdContentControlDropdownList. Error message something like "You are not allowed to change because the field is protected".
Is there any way to change the active item of a DropDownList?
private void setstatus(string status)
{
ContentControls ccList;
ccList = this.activeDocument.SelectContentControlsByTitle("Status");
ContentControl cc = ccList[1];
// works with wdContentControlText
// fails with wdContentControlDropdownList
cc.Range.Text = status;
}
There is a strange workaround - but it works. Assign type RichText to the content control, then change the text. Afterwards reassgin the old type. The content control in Word remains unaffected.
private void setstatus(string status)
{
ContentControls ccList;
ccList = this.activeDocument.SelectContentControlsByTitle("Status");
ContentControl cc = ccList[1];
cc.Type = WdContentControlType.wdContentControlRichText;
cc.Range.Text = status;
cc.Type = WdContentControlType.wdContentControlDropdownList;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.