Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DropDownListContentControl Class (2007 System)

Updated: July 2008

Represents a drop-down list on a document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

[DefaultBindingPropertyAttribute("PlaceholderText")]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class DropDownListContentControl : ContentControlBase, 
	ISupportInitializeControl, ISupportInitialize

A DropDownListContentControl displays a list of items that users can select.

To access the list of items in a DropDownListContentControl, use the DropDownListEntries property.

To enable users to choose from a list of items or add their own text to the control, use a ComboBoxContentControl.

Content Controls

The DropDownListContentControl is one of eight types of content controls that you can use to design documents and templates in Microsoft Office Word. Content controls have a user interface (UI) that has controlled input like a form. You can use content controls to prevent users from editing protected sections of the document or template, and you can also bind content controls to a data source. For more information, see Content Controls.

The following code example adds a new DropDownListContentControl to the beginning of the document. Users can select the name of a day of the week in the control.

This version is for a document-level customization. To use this code, paste it into the ThisDocument class in your project, and call the AddDropDownListControlAtSelection method from the ThisDocument_Startup method.

private Microsoft.Office.Tools.Word.DropDownListContentControl dropDownListControl1;

private void AddDropDownListControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();

    dropDownListControl1 = this.Controls.AddDropDownListContentControl("dropDownListControl1");
    dropDownListControl1.DropDownListEntries.Add("Monday", "Monday", 0);
    dropDownListControl1.DropDownListEntries.Add("Tuesday", "Tuesday", 1);
    dropDownListControl1.DropDownListEntries.Add("Wednesday", "Wednesday", 2);
    dropDownListControl1.PlaceholderText = "Choose a day";
}

This version is for an application-level add-in. To use this code, paste it into the ThisAddIn class in your project, and call the AddDropDownListControlAtSelection method from the ThisAddIn_Startup method.

private Microsoft.Office.Tools.Word.DropDownListContentControl dropDownListControl1;

private void AddDropDownListControlAtSelection()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();

    dropDownListControl1 = vstoDoc.Controls.AddDropDownListContentControl("dropDownListControl1");
    dropDownListControl1.DropDownListEntries.Add("Monday", "Monday", 0);
    dropDownListControl1.DropDownListEntries.Add("Tuesday", "Tuesday", 1);
    dropDownListControl1.DropDownListEntries.Add("Wednesday", "Wednesday", 2);
    dropDownListControl1.PlaceholderText = "Choose a day";
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft