Expand Minimize

DocumentBase.SelectContentControlsByTitle Method

Returns all the content controls in the document that have the specified title.

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

public ContentControls SelectContentControlsByTitle(
	string title
)

Parameters

title
Type: System.String

The title of the content controls to return.

Return Value

Type: Microsoft.Office.Interop.Word.ContentControls
A ContentControls collection that contains the content controls that have the specified title.

The following code example adds two paragraphs to the document and then adds one control to each new paragraph: a RichTextContentControl, and a ComboBoxContentControl. The example sets the Tag and Title properties of each control. Next, the code calls the SelectContentControlsByTitle method to get the collection of native content controls whose title equals Customer Title. It then modifies the placeholder text of each control in the returned collection, which in this case contains only the ComboBoxContentControl. To use this example, run it from the ThisDocument class in a document-level project.

private void ContentControlsTitle()
{                        
    Word.Paragraph par1 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.RichTextContentControl richTextControl = 
        this.Controls.AddRichTextContentControl(par1.Range, 
        "richTextControl");
    richTextControl.Tag = "Customer";
    richTextControl.Title = "Customer Name";

    Word.Paragraph par2 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl = 
        this.Controls.AddComboBoxContentControl(par2.Range, 
        "comboBoxControl");
    comboBoxControl.Tag = "Customer";
    comboBoxControl.Title = "Customer Title";

    Word.ContentControls myControls = 
        this.SelectContentControlsByTitle("Customer Title");
    foreach (Word.ContentControl ctrl in myControls)
    {                                
        ctrl.SetPlaceholderText(null, null, "Select a title.");                
    }
}

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft