Share via


DocumentBase.SelectContentControlsByTitle(String) Method

Definition

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

public:
 Microsoft::Office::Interop::Word::ContentControls ^ SelectContentControlsByTitle(System::String ^ title);
public Microsoft.Office.Interop.Word.ContentControls SelectContentControlsByTitle (string title);
member this.SelectContentControlsByTitle : string -> Microsoft.Office.Interop.Word.ContentControls
Public Function SelectContentControlsByTitle (title As String) As ContentControls

Parameters

title
String

The title of the content controls to return.

Returns

A ContentControls collection that contains the content controls that have the specified title.

Examples

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.");                
    }
}
Private Sub ContentControlsTitle()
    Dim par1 As Word.Paragraph = Me.Paragraphs.Add()
    Dim richTextControl As Microsoft.Office.Tools.Word.RichTextContentControl _
        = Me.Controls.AddRichTextContentControl(par1.Range, "richTextControl")
    richTextControl.Tag = "Customer"
    richTextControl.Title = "Customer Name"

    Dim par2 As Word.Paragraph = Me.Paragraphs.Add()
    Dim comboBoxControl As Microsoft.Office.Tools.Word.ComboBoxContentControl _
        = Me.Controls.AddComboBoxContentControl(par2.Range, "comboBoxControl")
    comboBoxControl.Tag = "Customer"
    comboBoxControl.Title = "Customer Title"

    Dim myControls As Word.ContentControls = _
        Me.SelectContentControlsByTitle("Customer Title")
    For Each ctrl As Word.ContentControl In myControls
        ctrl.SetPlaceholderText(Text:="Select a title.")
    Next
End Sub

Applies to