Share via


ComboBoxContentControl Interface

Represents a combo box on a document.

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

Syntax

'Declaration
<GuidAttribute("fff2d316-e224-4cd9-a10c-3edf95689a6d")> _
Public Interface ComboBoxContentControl _
    Inherits ContentControlBase, IBindableComponent, IComponent, IDisposable,  _
    ISupportInitialize
[GuidAttribute("fff2d316-e224-4cd9-a10c-3edf95689a6d")]
public interface ComboBoxContentControl : ContentControlBase, 
    IBindableComponent, IComponent, IDisposable, ISupportInitialize

The ComboBoxContentControl type exposes the following members.

Properties

  Name Description
Public property Application Gets a Application that represents the current instance of Microsoft Office Word.
Public property BindingContext Gets or sets the collection of currency managers for the IBindableComponent. (Inherited from IBindableComponent.)
Public property Container Infrastructure. (Inherited from ContentControlBase.)
Public property ContainerComponent Infrastructure. (Inherited from ContentControlBase.)
Public property Creator Gets a 32-bit integer that indicates the application in which the ComboBoxContentControl was created.
Public property DataBindings Gets the collection of data-binding objects for this IBindableComponent. (Inherited from IBindableComponent.)
Public property DefaultDataSourceUpdateMode Gets or sets the default DataSourceUpdateMode for the ContentControlBase. (Inherited from ContentControlBase.)
Public property DefaultTextStyle Gets the name of the character style that is used to format text in the ComboBoxContentControl.
Public property DropDownListEntries Gets the collection of items that are displayed by the ComboBoxContentControl.
Public property ID Gets a unique number that identifies the content control. (Inherited from ContentControlBase.)
Public property InnerObject Gets the underlying ContentControl object for the Microsoft.Office.Tools.Word.ContentControlBase. (Inherited from ContentControlBase.)
Public property LockContentControl Gets or sets a value that specifies whether the ComboBoxContentControl can be deleted from the document.
Public property LockContents Gets or sets a value that specifies whether the contents of the ComboBoxContentControl can be edited.
Public property MultiLine Gets or sets a value that specifies whether the ComboBoxContentControl can contain line breaks.
Public property Parent Gets the parent of the ComboBoxContentControl.
Public property ParentContentControl Gets the parent content control of a ComboBoxContentControl that is nested in another content control.
Public property PlaceholderText Gets or sets the text that is displayed in the ComboBoxContentControl until the text is changed by a user action or some other operation.
Public property Range Gets a Range that represents the contents of the ComboBoxContentControl.
Public property ShowingPlaceholderText Gets a value that indicates whether the ComboBoxContentControl is currently displaying placeholder text.
Public property Site Gets or sets the ISite associated with the IComponent. (Inherited from IComponent.)
Public property Tag Gets or sets a string that you want to associate with the ComboBoxContentControl.
Public property Temporary Gets or sets a value that specifies whether the ComboBoxContentControl is automatically deleted from the document when the control is edited.
Public property Text Gets or sets the text in the ComboBoxContentControl.
Public property Title Gets or sets the title of the ComboBoxContentControl.
Public property XMLMapping Gets an XMLMapping that represents the binding between the ComboBoxContentControl and an element in a custom XML part.

Top

Methods

  Name Description
Public method BeginInit Signals the object that initialization is starting. (Inherited from ISupportInitialize.)
Public method Copy Copies the ComboBoxContentControl from the document to the Clipboard.
Public method Cut Removes the ComboBoxContentControl from the document and adds it to the Clipboard.
Public method Delete Deletes a dynamically created content control from the document and removes it from the ControlCollection in the document. (Inherited from ContentControlBase.)
Public method Dispose Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
Public method EndInit Signals the object that initialization is complete. (Inherited from ISupportInitialize.)
Public method SetPlaceholderText Displays text that is in a T:Microsoft.Office.Interop.Word.BuildingBlock, a Range, or a string as the placeholder text in the ComboBoxContentControl.

Top

Events

  Name Description
Public event Added Occurs after the content control is added to the document. (Inherited from ContentControlBase.)
Public event BindingContextChanged Occurs when the value of the BindingContext property of the ContentControlBase changes. (Inherited from ContentControlBase.)
Public event ContentUpdating Occurs just before Microsoft Office Word updates the text in the content control, if the content control is bound to a custom XML part. (Inherited from ContentControlBase.)
Public event Deleting Occurs just before the content control is deleted from the document. (Inherited from ContentControlBase.)
Public event Disposed Represents the method that handles the Disposed event of a component. (Inherited from IComponent.)
Public event Entering Occurs when the user clicks in the content control, or when the cursor is moved into the content control programmatically. (Inherited from ContentControlBase.)
Public event Exiting Occurs when the user clicks outside the content control, or when the cursor is moved outside the content control programmatically. (Inherited from ContentControlBase.)
Public event StoreUpdating Occurs just before Microsoft Office Word updates data in a custom XML part that is bound to the content control (that is, after the text in the content control changes). (Inherited from ContentControlBase.)
Public event Validated Occurs when the content control has been successfully validated. (Inherited from ContentControlBase.)
Public event Validating Occurs when the contents of the content control are being validated. (Inherited from ContentControlBase.)

Top

Remarks

A ComboBoxContentControl displays a list of items that users can select. Users can also type their own text in a ComboBoxContentControl.

To display a drop-down list of items in a text box that users cannot edit, use a DropDownListContentControl.

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

Note

This interface is implemented by the Visual Studio Tools for Office runtime. It is not intended to be implemented in your code. For more information, see Visual Studio Tools for Office Runtime Overview.

Content Controls

The ComboBoxContentControl 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.

Usage

This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4 and the .NET Framework 4.5. In projects that target the .NET Framework 3.5, this type might have different members and the code examples provided for this type might not work. For documentation about this type in projects that target the .NET Framework 3.5, see the following reference section in the Visual Studio 2008 documentation: https://go.microsoft.com/fwlink/?LinkId=160658.

Examples

The following code example adds a new ComboBoxContentControl to the beginning of the document. Users can select a color name displayed by the control, or they can type the name of a new color.

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

Dim comboBoxControl1 As Microsoft.Office.Tools.Word.ComboBoxContentControl

Private Sub AddComboBoxControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    comboBoxControl1 = Me.Controls.AddComboBoxContentControl("comboBoxControl1")
    With comboBoxControl1
        .DropDownListEntries.Add("Red", "Red", 0)
        .DropDownListEntries.Add("Green", "Green", 1)
        .DropDownListEntries.Add("Blue", "Blue", 2)
        .PlaceholderText = "Choose a color, or enter your own" 
    End With 
End Sub
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl1;

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

    comboBoxControl1 = this.Controls.AddComboBoxContentControl("comboBoxControl1");
    comboBoxControl1.DropDownListEntries.Add("Red", "Red", 0);
    comboBoxControl1.DropDownListEntries.Add("Green", "Green", 1);
    comboBoxControl1.DropDownListEntries.Add("Blue", "Blue", 2);
    comboBoxControl1.PlaceholderText = "Choose a color, or enter your own";
}

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 AddComboBoxControlAtSelection method from the ThisAddIn_Startup method.

Dim comboBoxControl1 As Microsoft.Office.Tools.Word.ComboBoxContentControl

Private Sub AddComboBoxControlAtSelection()
    If Me.Application.ActiveDocument Is Nothing Then 
        Return 
    End If 

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    vstoDoc.Paragraphs(1).Range.Select()
    comboBoxControl1 = vstoDoc.Controls.AddComboBoxContentControl("comboBoxControl1")
    With comboBoxControl1
        .DropDownListEntries.Add("Red", "Red", 0)
        .DropDownListEntries.Add("Green", "Green", 1)
        .DropDownListEntries.Add("Blue", "Blue", 2)
        .PlaceholderText = "Choose a color, or enter your own" 
    End With 
End Sub
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl1;

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

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

    comboBoxControl1 = vstoDoc.Controls.AddComboBoxContentControl(
        "comboBoxControl1");
    comboBoxControl1.DropDownListEntries.Add("Red", "Red", 0);
    comboBoxControl1.DropDownListEntries.Add("Green", "Green", 1);
    comboBoxControl1.DropDownListEntries.Add("Blue", "Blue", 2);
    comboBoxControl1.PlaceholderText = "Choose a color, or enter your own";            
}

See Also

Reference

Microsoft.Office.Tools.Word Namespace

Other Resources

Content Controls

How to: Add Content Controls to Word Documents

How to: Protect Parts of Documents by Using Content Controls

Walkthrough: Creating a Template By Using Content Controls